我在尝试阅读Soap响应时遇到了问题。 它试图读取一些不存在的元素。 可能是什么问题?
Python:2.6.6
lxml:2.2.3.0
我的代码:
from lxml import etree
testFile = open('test.xml', 'r')
tree = etree.iterparse(testFile, tag='{http://host.com/Domain}dataRow')
for event, elem in tree:
print("ID: " +elem.get('id'))
这是我试图阅读的xml:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:GetDataRows xmlns:ns2="http://host.com/Domain">
<ns2:dataRow id="1"></ns2:dataRow>
<ns2:dataRow id="2"></ns2:dataRow>
</ns2:GetDataRows>
</soapenv:Body>
回溯:
Traceback (most recent call last):
File "test.py", line 6, in <module>
for event, elem in tree:
File "iterparse.pxi", line 515, in lxml.etree.iterparse.__next__ (src/lxml/lxml.etree.c:86643)
File "parser.pxi", line 576, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:64260)
lxml.etree.XMLSyntaxError: None