我正在使用Python lxml读取下面的xml文件,但无法访问节点
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<licenses>
<license>
<serial id>1234</serialid>
<key>
<Product>Test Producet</Product>
<Start>Jan</Start>
<key>
</license>
</licenses>
Python代码
tree = etree.parse('test.slf')
root = tree.getroot()
print 'root = ', root[0][0].findall('key')
#print 'root findall = ', root.getroottree('key')
for node in root.findall('key'):
print node
答案 0 :(得分:0)
for node in tree.xpath('//key'):
print node
顺便说一下,你的xml中有两个拼写错误:取出<serial id>
开头标记中的空格,并将/
添加到结束<key>