By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,278 Members | 2,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,278 IT Pros & Developers. It's quick & easy.

Problem parsing SOAP envelope with ElementTree

P: n/a
Hi All,

Can someone tell me why id the following not working?
I have a soap response envelope, for test purpose it's just a string
and I create ElementTree from it.
Then I try to find Response tag, but I get None.
data = """<soap:Envelope xmlns:soap="
soap/envelope/" xmlns:xsi=""
<soap:Body<Get2Response xmlns="http://">
<Get2Result><![CDATA[<?xml version='1.0'
encoding='UTF-8'?<Response<Entity Name='Accounts'
Current='00300571B42F1DEC8E9B6CDF19A59950'<Instanc e
Name='Status' Value='2'/<Field Name='Id' Value='MC4670'/<Field
Name='Name' Value='ACDC Industries Inc'/>
<Field Name='City' Value='Milwaukee'/<Field
Name='MainContact' Value=''/<Field Name='CreatedOn'
Value='20070723051316.0000000 '/</Instance</Entity </

ElementTree.XMLTreeBuilder = SimpleXMLTreeBuilder.TreeBuilder

if dom == None:
return "Empty Dom"

response = dom.find('{
if response == None:
return "Empty Response"

if I try to use
response = dom.find('{}Response') this doesn't work

What am I doing wrong?
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Zvi wrote:
Hi All,

Can someone tell me why id the following not working?
snip not working code
What am I doing wrong?
Here is working code.

from xml.etree import ElementTree as ET

data = """<soap:Envelope
<Get2Response xmlns="">
<Get2Result><![CDATA[<?xml version='1.0' encoding='UTF-8'?>
<Entity Name='Accounts' Current='00300571B42F1DEC8E9B6CDF19A59950'>
<Instance Id='00300571B42F1DEC8E9B6CDF19A59950'>
<Field Name='Status' Value='2'/>
<Field Name='Id' Value='MC4670'/>
<Field Name='Name' Value='ACDC Industries Inc'/>
<Field Name='City' Value='Milwaukee'/>
<Field Name='MainContact' Value=''/>
<Field Name='CreatedOn' Value='20070723051316.0000000 '/>

env = ET.fromstring(data)
result = env.find('*//{}Get2Result')
response = ET.fromstring(result.text)
for elm in response.getiterator():
print elm

In the future please paste complete examples. It helps me to help you.
They were two things that I found to be wrong:
- searching using wrong path. You missed *// in front of the tag
- parsing only once. There are two xml sources here.
The first parse got you the representation of the Envelope.
You have to parse the Get2Result payload to get at the
interesting part

Jun 27 '08 #2

P: n/a
On May 7, 1:12*am, Waldemar Osuch <waldemar.os...@gmail.comwrote:
Thanks a lot :)
P.S. It was a complete code, I didn't write anything else.
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.