I have a not-so-well formed XML with hyphens inside the tag names, which I want to replace with underscores (to be able to work with lxml.objectify). I want to replace ALL tag names, including nested childs.
A sample XML:
<job>
<server>
<cpu-set>
</cpu-set>
</server>
<ip-routings>
</ip-routings>
</job>
I want to convert this XML in a clean way (without regexes but with an XML lib like lxml) to this one:
<job>
<server>
<cpu_set>
</cpu_set>
</server>
<ip_routings>
</ip_routings>
</job>
What would be a pythonic and clean way to do that?
Use xpath to find the elements with hyphens and re-write tags:
Yields: