I am a python newbie. I would like to efficiently (for memory sake) write to different specific paths of an xml file and recursively save different variations of the xml file. The XML file is over 100k lines and deeply nested.
to illustrate. Given the psuedo code (jerry.xml),
<data>
<country name="Liechtenstein">
<rank updated="yes">2</rank>
<language>english</language>
<currency>1.21$/kg</currency>
<gdppc>141100</gdppc>
<gdpnp>2.304e+0150</gdpnp>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank updated="yes">5</rank>
<language>english</language>
<currency>4.1$/kg</currency>
<gdppc>59900</gdppc>
<gdpnp>5.2e-015</gdpnp>
<neighbor name="Malaysia" direction="N"/>
</country>
How can I recursively write to and save different variations of this XML(jerry.xml), such that the only difference at each instance is only a change in one of the element text. E.g. Only difference between jerry.xml and new_jerry.xml for first instance is that country "Liechtenstein" gdppc is now 500000 not 141100. Is there a way to efficiency loop through and do this for all element texts?
I think I can use a for path in root.iterfind('path'): and tree.write(new_jerry.xml) but I would need to find paths first.
Any help would be appreciated.
No comments:
Post a Comment