Howto write XML file with comments?

  • Thread starter Alexander Eisenhuth
  • Start date
A

Alexander Eisenhuth

Hello,

- I've to write a XML document including comments
- 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?

Any help or hints are very welcome

Thanks
Alexander
 
S

Stefan Behnel

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
 
A

Alexander Eisenhuth

Stefan said:
Alexander Eisenhuth, 08.07.2010 11:08:

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

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

Data is present as tags and attributes
All of that has an impact on the 'right' answer.



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.

Is the API of cElementTree different from ElementTree in the python standard
library?
 
S

Stefan Behnel

Alexander Eisenhuth, 08.07.2010 12:07:
write means write to a file

You seam to imply that it's obvious what you want to do. From the little
information that you give us, it's not.

Data is present as tags and attributes

Whatever that is supposed to mean in this context.


.... and it still does.

Is the API of cElementTree different from ElementTree in the python
standard library?

Same thing, different import.

Note that both were updated in Py2.7, BTW.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top