2 回答

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊
使用lxml和XPath:
from StringIO import StringIO
from lxml import etree
xml = """<root>
<note>
<id>51</id>
<Name>Jani</Name>
<city>Frankfurt</city>
<IQ>Intelligent</IQ>
</note>
<note>
<id>71</id>
<Name>Peter</Name>
<city>Paris</city>
<IQ>Average</IQ>
</note>
<note>
<id>81</id>
<Name>Asho</Name>
<city>Paris</city>
<IQ>Intelligent</IQ>
</note>
</root>"""
tree = etree.parse(StringIO.StringIO(xml))
for note in tree.xpath("//note[IQ='Intelligent']"):
print note.getchildren()[1].tag + "=" + note.getchildren()[1].text
打?。?/p>
Name=Jani
Name=Asho
添加回答
舉報(bào)