Question

Suds is returning sub group XML elements as a long strings of 'x = "y"' as seen below. How can I get sub xml elements to return into a data set so I dont have to write string parsing code?

Details:

I call a web service with suds as normal like this:

myWebServiceData=client.service.getMethod("P1", "P2", "P3")

It Returns a dictionary as I would like however it looks like this:

myWebServiceData = { elm1: "data1", elm2: "data2", elm3: ["(data3){ elm4 = data4 elm5 = data5 elm6 = data6" ]}

So any data under data4 is a list with a length of 1. like this:

print myWebServiceData['elm4'][0]
elm4 = "data4" 
elm5 = "data5"
elm6 = "data6

"

However my xml looks like this (as seen in my logger):

<elm1>data1</elm1>
<elm2>data2</elm2>
<elm3>
   <elm4>data4</elm4>
   <elm5>data5</elm5>
   <elm6>data6</elm6>
</elm3>
Was it helpful?

Solution

As it turns out you the string given can easily be converted into a dictionary:

myElm3Dict = dict(myWebServiceData['elm3'][0])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top