Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43759 > unrolled thread

Parsing soap result

Started byOmbongi Moraa Fe <moraa.lovetakes2@gmail.com>
First post2013-04-17 16:50 +0300
Last post2013-04-17 12:14 -0700
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Parsing soap result Ombongi Moraa Fe <moraa.lovetakes2@gmail.com> - 2013-04-17 16:50 +0300
    Re: Parsing soap result darnold <darnold992000@yahoo.com> - 2013-04-17 10:55 -0700
      Re: Parsing soap result Christian Heimes <christian@python.org> - 2013-04-17 20:05 +0200
        Re: Parsing soap result darnold <darnold992000@yahoo.com> - 2013-04-17 12:14 -0700

#43759 — Parsing soap result

FromOmbongi Moraa Fe <moraa.lovetakes2@gmail.com>
Date2013-04-17 16:50 +0300
SubjectParsing soap result
Message-ID<mailman.723.1366206668.3114.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

My

client.service.gere(ri)

method call logs the below soap response in my log file.

<?xml version="1.0" encoding="utf-8" ?><soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:gere
xmlns:ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local
"><ns1:result><address>254727</address><deliveryStatus>DeliveredToNetwork</deliveryStatus></ns1:result></ns1:gere></soapenv:Body></soapenv:Envelope>


If I assign the client.service.gere(ri) to a variable, i get the output on
my screen:

result=client.service.gere(ri)

output:
[(DeliveryInformation){
   address = "254727"
   deliveryStatus = "DeliveredToNetwork"
 }]

string functions replace() and strip don't work.

how do I use xml.etree.ElementTree to print the parameters address and
deliveryStatus? Or is there a better python method?

Thanks in advance.

Saludos

Ombongi Moraa Faith

[toc] | [next] | [standalone]


#43770

Fromdarnold <darnold992000@yahoo.com>
Date2013-04-17 10:55 -0700
Message-ID<28fde565-f8c0-4995-b5a1-2ac2509712dc@l5g2000yqe.googlegroups.com>
In reply to#43759
On Apr 17, 8:50 am, Ombongi Moraa Fe <moraa.lovetak...@gmail.com>
wrote:

> how do I use xml.etree.ElementTree to print the parameters address and
> deliveryStatus? Or is there a better python method?
>


I'm sure there are prettier ways to do this, but you can use XPath
syntax to find all of your ns1:result nodes and loop through them:

>>> import xml.etree.ElementTree as ET
>>> myXML = '''\
<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:gere xmlns:ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/
local">
<ns1:result>
<address>254727</address>
<deliveryStatus>DeliveredToNetwork</deliveryStatus>
</ns1:result>
</ns1:gere>
</soapenv:Body>
</soapenv:Envelope>
'''
>>> myNamespaces=dict(ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local",soapenv="http://schemas.xmlsoap.org/soap/envelope/")
>>> root = ET.fromstring(myXML)
>>> for result in root.findall('.//ns1:result',namespaces=myNamespaces):
	address = result.find('address').text
	deliveryStatus = result.find('deliveryStatus').text
	print "address: %s, deliveryStatus: %s" % (address,deliveryStatus)


address: 254727, deliveryStatus: DeliveredToNetwork
>>>

HTH,
Don

[toc] | [prev] | [next] | [standalone]


#43771

FromChristian Heimes <christian@python.org>
Date2013-04-17 20:05 +0200
Message-ID<mailman.730.1366221958.3114.python-list@python.org>
In reply to#43770
Am 17.04.2013 19:55, schrieb darnold:
> On Apr 17, 8:50 am, Ombongi Moraa Fe <moraa.lovetak...@gmail.com>
> wrote:
> 
>> how do I use xml.etree.ElementTree to print the parameters address and
>> deliveryStatus? Or is there a better python method?
>>
> 
> 
> I'm sure there are prettier ways to do this, but you can use XPath
> syntax to find all of your ns1:result nodes and loop through them:

You want all {http://www.csapi.org/schema/parlayx/sms/send/v2_2/
local}result tags. The prefix isn't fixed.

[toc] | [prev] | [next] | [standalone]


#43777

Fromdarnold <darnold992000@yahoo.com>
Date2013-04-17 12:14 -0700
Message-ID<f35581ce-f123-40a8-b140-38c252713397@y12g2000yqb.googlegroups.com>
In reply to#43771
On Apr 17, 1:05 pm, Christian Heimes <christ...@python.org> wrote:
> Am 17.04.2013 19:55, schrieb darnold:
>
> > On Apr 17, 8:50 am, Ombongi Moraa Fe <moraa.lovetak...@gmail.com>
> > wrote:
>
> >> how do I use xml.etree.ElementTree to print the parameters address and
> >> deliveryStatus? Or is there a better python method?
>
> > I'm sure there are prettier ways to do this, but you can use XPath
> > syntax to find all of your ns1:result nodes and loop through them:
>
> You want all {http://www.csapi.org/schema/parlayx/sms/send/v2_2/
> local}result tags. The prefix isn't fixed.

I'm sorry, but I'm not understanding the difference.
By specifying:

>>> myNamespaces=dict(ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local")

Isn't this:

>>> for result in root.findall('.//ns1:result',namespaces=myNamespaces):

equivalent to:

>>> for result in root.findall('.//{http://www.csapi.org/schema/parlayx/sms/send/v2_2/local}result'):

?

Or am I misunderstanding? Is there a namespace-agnostic way of doing
this?
Admittedly, I haven't used ElementTree or XPath much prior to toying
with them to (attempt to) answer the OP's question.

Thanks for your patience,
Don

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web