Howto write XML file with comments?

Stefan Behnel stefan_ml at behnel.de
Thu Jul 8 05:43:29 EDT 2010


Alexander Eisenhuth, 08.07.2010 11:08:
> - I've to write a XML document including comments

"write" in the sense of typing in a text editor? Or constructing one 
programmatically in memory? Or ... ?

And what kind of data from what kind of source do you want to put into the 
document?

All of that has an impact on the 'right' answer.


> - the document should be formatted that it could be viewed with a text
> editor
>
> What is the fastest (time for realization) approach doing it in python 2.5?

If you mean to build an XML document programmatically, potentially using 
data that you get from somewhere, take a look at cElementTree. There's also 
a short recipe for pretty printing the tree before writing it out.

Stefan




More information about the Python-list mailing list