What does "not as reliable" mean here? The reason ElementSoap uses a parser wrapper is that the standard parser doesn't preserve namespace prefixes, which are needed to resolve things like XSI types, fault codes, and other places where SOAP puts prefixes in parsed content.
It is just an oberservation.
This is something we get as a result from a webservice:
--------------------------------------------------------
from elementsoap.ElementSOAP import namespace_parse
import elementtree.ElementTree as ET
Thanks for the sample. I'll look into this as soon as I find the time.
Update: Your sample code is setting a class attribute (Myfile.isread) instead of an instance attribute (self.isread). Since class attributes are shared between all instances of a class, the second Myfile instance will always return an empty string -- which causes the second parser to raise a "ParseError: no element found" exception. If I fix that, both parsers successfully parse that XML snippet.
What does "not as reliable" mean here? The reason ElementSoap uses a parser wrapper is that the standard parser doesn't preserve namespace prefixes, which are needed to resolve things like XSI types, fault codes, and other places where SOAP puts prefixes in parsed content.
It is just an oberservation.
This is something we get as a result from a webservice:
--------------------------------------------------------
from elementsoap.ElementSOAP import namespace_parse
import elementtree.ElementTree as ET
xmltext = """<?xml version="1.0" encoding="ISO-8859-1" ?><ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"><ns0:Body><ns1:getMasterDataResponse xmlns:ns1="XeriAPI"><resultList command="getMasterData" version="1.0">
<user>
<title value="Jan"/>
</user>
<doctype>
<title value="Richtlinie T"/>
<title value="Formular"/>
</doctype>
<process>
<title value="Controlling"/>
</process>
<department>
<title value="Integral Development GmbH"/>
</department>
<category>
<title value="Beschaffung / Purchase"/>
</category>
<responsibleUnit>
<title value="Support"/>
</responsibleUnit>
<location>
<title value="Stockholm"/>
<title value="Paris"/>
<title value="Hamburg"/>
</location>
</resultList></ns1:getMasterDataResponse></ns0:Body></ns0:Envelope>
"""
class Myfile:
isread = False
def read(self, *args, **kw):
if Myfile.isread:
return ""
Myfile.isread = True
return xmltext
try:
res = ET.parse(Myfile())
print "ET.parse worked:", res
except:
print "ET.parse error!"
try:
res = namespace_parse(Myfile())
print "namespace_parse worked:", res
except:
print "namespace_parse error!"
--------------------------------------------------------
Thanks for the sample. I'll look into this as soon as I find the time.
Update: Your sample code is setting a class attribute (Myfile.isread) instead of an instance attribute (self.isread). Since class attributes are shared between all instances of a class, the second Myfile instance will always return an empty string -- which causes the second parser to raise a "ParseError: no element found" exception. If I fix that, both parsers successfully parse that XML snippet.
Opps, you are right. I have originally used it in the running system. And cutted some XML away. I will check again.