使用 LXML 读取 SOAP 响应时出错
Error reading SOAP response with LXML
我在尝试读取 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
这似乎是 lxml 中的错误:
我在尝试读取 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
这似乎是 lxml 中的错误: