![](https://secure.gravatar.com/avatar/1e2caa78f917e18fc081fed2f2058af7.jpg?s=120&d=mm&r=g)
Le 01/11/2012 22:56, Stefan Behnel a écrit :
Actually, I'd love to see someone implement a magic API like this:
# open an "XMLFile" object that knows about XML serialisation with xmlfile("somefile.xml", encoding='utf-8') as xf: # generate an element (the root element) with xf.Element('root-tag') as root_element: # generate content, e.g. through iterparse for element in generate_some_elements(): # serialise generated elements into the XML file xf.write(element)
That looks like it should be totally trivial to do, but would make the above use case way simpler and safer.
I’ve seen this kind of thing called a "SAX-like serializer". http://hsivonen.iki.fi/producing-xml/ (This page has tons of advice on producing XML) Cheers, -- Simon Sapin