On Thu, Nov 17, 2011 at 4:47 PM, Balachandran Sivakumar
<benignb...@gmail.com> wrote:
> Hi,
>
>             I have to parse an xml file, get to a spefic node, and
> set it to a different value and write it back to the file. What is the
> best way to do it ? The xml file can be a few hundred lines(with
> proper formatting).
[...]
> But I don't really know how to update an entry and write it back to
> the xml file ? Can someone suggest some ways please ? Also, it is
> necessary that it should be XPath based. Thanks
[...]

To update an element, just assign a value to it, e.g.,
  myelem.text = "New value"
You can then save the modified XML to a new file.
Please see http://infohost.nmt.edu/tcc/help/pubs/pylxml/web/modifying.html

That same tutorial,
http://infohost.nmt.edu/tcc/help/pubs/pylxml/web/index.html ,
 also describes various ways of addressing elements. This is also a useful
tutorial: http://lxml.de/tutorial.html

Regards,
Gora
_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to