Editing XML file content with Python.
Posted
by Hooloovoo
on Stack Overflow
See other posts from Stack Overflow
or by Hooloovoo
Published on 2010-06-01T15:32:50Z
Indexed on
2010/06/01
15:33 UTC
Read the original article
Hit count: 135
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.
© Stack Overflow or respective owner