這裏是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