Editing XML file content with Python.
- by Hooloovoo
Hi,
I am trying to use Python to read in an XML file containing some parameter names and values, e.g.
...
<parameter name='par1'>
<value>24</value>
</parameter>
<parameter name='par2'>
<value>Blue/Red/Green</value>
</parameter>
...
and then pass it a dictionary with the parameter names {'par1':'53','par2':'Yellow/Pink/Black',...} and corresponding new values to replace the old ones in the XML file. The output should then overwrite the original XML file.
At the moment I am converting the XML to a python dictionary and after some element comparison and regular expression handling, writing the output again in XML format.
I am not too happy with this and was wondering whether anyone can recommend a more efficient way of doing it?
Thanks.