0

如果我有以下 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

IE

concept1 {'id': '001', 'code': '246545002'}
concept2 {'id': '002', 'code': '938374749'}

如何访问属性值?即看看codeforconcept1是否等于codefor concept2

4

0 回答 0