这里是XML:Python的elementree有很难提取数据
<top>
<target>
<name>TARGET_NAME_1</name>
<error_count>5</error_count>
<error_examples>a string goes here</error_examples>
</target>
<target>
<name>TARGET_NAME_2</name>
<error_count>5</error_count>
<error_examples>a string goes here</error_examples>
</target>
</top>
这里是我尝试:
tree = ETREE.parse(str(XML_FILE_PATH)) #this seems to work
top = tree.getroot()
targets = top.findall('target')
for target in targets:
print target
这给了我<Element target at HEX_NUMBER>
。那么如何提取每个目标的价值,即TARGET_NAME_1
?
干杯
编辑 - 我要指出,我在Python版本2.6
是的,这似乎工作。我对这样做并不是疯狂的,但我现在只是想要一起破解一些东西。 – JDS 2012-07-12 22:11:48