This question is a little difficult to articulate with my inadequate English but I will do my best.
I have a directory of xml files, each file contains xml such as:
<root>
<fields>
<field>
<description/>
<region id="Number.T2S366_R_487" page="1"/>
</field>
<field>
<description/>
<region id="Number.T2S366_R_488.`0" page="1"/>
<region id="String.T2S366_R_488.`1" page="1"/>
</field>
</fields>
</root>
I'd like to do a String replacement on the lines which contain the dot, tick, number notation such as .`0 with an index notation like [0],[1], [2], ... and so forth.
So the transformed xml payload should look like something below:
<root>
<fields>
<field>
<description/>
<region id="Number.T2S366_R_487" page="1"/>
</field>
<field>
<description/>
<region id="Number.T2S366_R_488[0]" page="1"/>
<region id="String.T2S366_R_488[1]" page="1"/>
</field>
</fields>
</root>
How can I accomplish this using python? This seems fairly straight forward to do using regex but that would be difficult to do for a directory of files containing multiple files. I'd like to see an implementation using python 3.x, as I am learning it.
lxmllibrary for Python3: lxml.de/installation.html