如果我有以下xml:
<?xml version="1.0" encoding="UTF-8"?>
<dat>
<concept1 id="001" code="246545002"/>
<concept1 id="002" code="938374749"/>
</dat>
我可以通过
找到所有concept1
分支
import xml.etree.cElementTree as ET
tree = ET.ElementTree(file='negation.xmi')
root = tree.getroot()
for elem in tree.iterfind('concept1'):
print elem.tag, elem.attrib
即
concept1 {'id': '001', 'code': '246545002'}
concept2 {'id': '002', 'code': '938374749'}
如何访问属性值?即查看code
的{{1}}是否等于concept1
的{{1}}?