Using file objects with elementtree
Diez B. Roggisch
deets at nospam.web.de
Wed May 14 18:41:00 EDT 2008
dj schrieb:
> Hello,
>
> Rather then holding my XML document in memory before writing it to
> disk, I want to create a file object that elementtree will write each
> element to has it is created. Does any one know how to do that ?
>
> Here is my code so, far:
>
> fd = open("page.xml", "w")
> tree.write( fd, encoding="iso-8859-1")
>
> I know there's something I am doing wrong, but I just do not know
> what.
This isn't possible. How should ET handle the case that you add a
child-node to a node that has been rendered already?
What you could try is to serialize subtrees that are closed to a stream.
Diez
More information about the Python-list
mailing list