[英]Reading xml file using Python lxml
我正在使用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
for node in tree.xpath('//key'):
print node
順便說一句,您的xml中有2種錯別字:取出<serial id>
開始標記中的空格,並添加/
到結束<key>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.