0
我有一个XML文件,我需要提取特征标签内部的所有文本在Python如何从XML标记值在Python
<person>
<text id="1">
<title>
student
</title>
<feature>
xxxx
<name>yyyy</name>
zzzz
<country>dddd</country>
ffff
</feature>
我的代码是这样的:
for person in tree.iter():
for text in person:
for feature in text:
if feature.tag=="feature":
print(feature.text)
它只显示我的“xxxx”,但我的理想的答案是 XXXX YYYY ZZZZ DDDD FFFF
让XML节点包含文本内容和其他XML节点是非常不寻常的。可能为什么你有问题。 – Dijkgraaf