我有这样的xml:
<rule>
<word>I</word>
<word>need</word>
<word>more</word>
<marker>
<word>money</word>
</marker>
<word>now</word>
</rule>
我可以通过以下方式获取文本:
import xml.etree.ElementTree as ET
tree = ET.parse("1.xml")
for rule in tree.iter("rule"):
for word in rule.iter("word"):
print "%s" % word.text,
我会得到:
I need more money now
如何将标记标签替换为(和 /marker 为)。换句话说,结果必须是:
I need more (money) now
elementtree可以吗?提前致谢!