From: Alexander Eisenhuth on 8 Jul 2010 05:08 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
From: Stefan Behnel on 8 Jul 2010 05:43 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
From: Alexander Eisenhuth on 8 Jul 2010 06:07 Stefan Behnel schrieb: > 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 ... ? 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. > > >> - 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. Is the API of cElementTree different from ElementTree in the python standard library? > > Stefan >
From: Stefan Behnel on 8 Jul 2010 06:26 Alexander Eisenhuth, 08.07.2010 12:07: > Stefan Behnel schrieb: >> 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 ... ? > > 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. >> 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 Whatever that is supposed to mean in this context. >> All of that has an impact on the 'right' answer. .... and it still does. >>> - 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. > > 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
From: Alexander Eisenhuth on 8 Jul 2010 06:54 Sorry for my little riddle, but you solved it quite good with: - http://effbot.org/zone/element-lib.htm#prettyprint and comments are also in ElementTree (xml.etree.ElementTree.Comment) Thanks Stefan Behnel schrieb: > Alexander Eisenhuth, 08.07.2010 12:07: >> Stefan Behnel schrieb: >>> 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 ... ? >> >> 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. > > >>> 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 > > Whatever that is supposed to mean in this context. > > >>> All of that has an impact on the 'right' answer. > > ... and it still does. > > >>>> - 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. >> >> 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 >
|
Pages: 1 Prev: simple python deployment tool Next: Writing Out from 2 Lists |