我有一个示例xml文档
<?xml version="1.0" encoding="UTF-8"?>
<school xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.school.org">
<name>John</name>
<name>Ferus</name>
<name>Greg</name>
</school>
我有以下python代码来查找名称,
import xml.etree.ElementTree as ElementTree
with open('sample.xml', 'rt') as f:
tree = ElementTree.parse(f)
root = tree.getroot()
for name in root.findall("{http://www.school.org}name"):
print name.text
每次搜索标签时提供命名空间都很笨拙。还有更好的方法吗?