<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
<first-name>First_Name</first-name>
<last-name>Last_Name</last-name>
<headline>Headline</headline>
<location>
<name>Some_city, STATE </name>
<country>
<code>us</code>
</country>
</location>
</person>
我正在尝试访问First_Name,Last_Name,Headline和Some_city,STATE
到目前为止,我有:
import xml.etree.ElementTree as ET
tree = ET.parse(data)
root = tree.getroot()
for child in root:
print child
打印出:
<Element 'first-name' at 0x110726b10>
<Element 'last-name' at 0x110726b50>
<Element 'headline' at 0x110726b90>
<Element 'location' at 0x110726bd0>
如何访问“名字”的值?
获取.text
属性:
for child in root:
print child.text
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句