david farning <df******@localhost.localdomain> wrote in message news:<Pz********************@newssrv26.news.prodig y.com>...
I am doing my first work in python/xml
Is is possiable to write a xmlTree in a single command?
for example
doc = libxml2.parseFile (filename)
# add node to doc
doc.write(filename) ??????????????
I have seen several examles writing one element or line at a time, but never
the whole tree.
You can use the serialize method on the document node to get the
document as text (or on any other node to get a document fragment as
text):
s = doc.serialize()
# Use normal file writing mechanisms.
Or you could use the saveFile method to write to a file:
doc.saveFile(filename)
I'd recommend using Python interactively to see which methods are
available on the document node:
import libxml2
doc = libxml2.parseFile(filename)
dir(doc)
Indeed, until I started responding to your question, I hadn't noticed
saveFile, so there's a lot to discover. ;-)
Paul