How To Change Different Hierarchy Tags With Lxml?
I want to change all tags names
to
tag and the first inner con
Solution 1:
I think you're overcomplicating it. Just find all of the p
elements (with .xpath()
or .findall()
) and change the value of the .tag property...
from lxml import etree
tree = etree.parse("73-20.xml")
for p in tree.findall(".//p"):
p.tag = "paragraph"
tree.write("FerNewtags.xml")
Output (FerNewtags.xml)
<dita><topicid="id15CDB0PL09E"><titleid="id15CDB0R0VYB"><?FM MARKER [Header/Footer $1] All?>Control
</title><shortdesc>CONTROL</shortdesc><conceptid="id15CDB0Q0Q4G"><titleid="id15CDB0R0VHA">General
</title><conbody><paragraph>This section
</paragraph></conbody><conceptid="id156F7H00GIE"><titleid="id15CDB0R0V1W">System
</title><conbody><paragraph>Engine
</paragraph><paragraph>The ECU
</paragraph><paragraph>The aircraft
</paragraph><paragraph>The system
</paragraph></conbody></concept></concept></topic></dita>
Post a Comment for "How To Change Different Hierarchy Tags With Lxml?"