tags:

views:

53

answers:

2

I have been looking for a while a python module/API that does something I believe is quite simple:

  1. Read an XML file
  2. Add/Edit/Remove entries

So far I've found several snippets that interface with complicated object oriented databases, but nothing dead simple as:

xml = etree.parse ('file.xml')

xml.add(xpath, new_node(attrs))
xml.remove(xpath)
xml.edit(xpath, new_attrs(attrs))
xml.write()

Most surely I'm misunderstanding the API, but some light will be very welcome.

Thanks in advance !

+1  A: 

Did you checkout the lxml.etree tutorial? It has enough examples to show you how to do most of what you want.

Manoj Govindan
A: 

There are solutions from the standard library too. I think clear() from xml.etree.ElementTree should work as desired. On the other hand, if you have no problem with external dependencies, I think, not sure though, that lxml provides a faster solution.

myle