brainstorm
brainstorm

Reputation: 750

simple python lxml CRUD?

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 !

Upvotes: 0

Views: 365

Answers (2)

Dimitris Leventeas
Dimitris Leventeas

Reputation: 1702

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.

Upvotes: 0

Manoj Govindan
Manoj Govindan

Reputation: 74705

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

Upvotes: 2

Related Questions