Re: [Tutor] Elementtree and pretty printing in Python 2.7
Hello Jerry, Tricky solution using minidom (standard) Not tested: import ElementTree import minidom def prettyPrint(element): txt = ElementTree.tostring(element) print minidom.parseString(txt).toprettyxml() Regards Karim On 08/22/2010 04:51 PM, Jerry Hill wrote: On Fri, Aug 20, 2010 at 3:49 AM, Knacktus wrote: Hi guys, I'm using Python 2.7 and the ElementTree standard-lib to write some xml. My output xml has no line breaks! So, it looks like that: instead of something like this: I'm aware of lxml which seems to have a pretty print option, but I would prefer to use the standard-lib ElementTree which seems not to have a feature like this. Do I miss something using the ElementTree-lib or is it bug? Neither, as far as I know. The XML you get is perfectly valid XML. If you want to pretty print it, there's a recipe here: http://effbot.org/zone/element-lib.htm#prettyprint, but I don't think it's been included in the standard library yet. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Elementtree and pretty printing in Python 2.7
Jerry Hill, 22.08.2010 16:51: Neither, as far as I know. The XML you get is perfectly valid XML. It's clearly well-formed, but I can't see it being valid without some kind of schema to validate it against. Note that the OP has already written a follow-up but forgot to reply to the original mail. Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Elementtree and pretty printing in Python 2.7
Sorry wrong import! from xml.minidom import parseString from xml.etree import ElementTree Karim On 08/22/2010 05:24 PM, Karim wrote: Hello Jerry, Tricky solution using minidom (standard) Not tested: import ElementTree import minidom def prettyPrint(element): txt = ElementTree.tostring(element) print minidom.parseString(txt).toprettyxml() Regards Karim On 08/22/2010 04:51 PM, Jerry Hill wrote: On Fri, Aug 20, 2010 at 3:49 AM, Knacktus wrote: Hi guys, I'm using Python 2.7 and the ElementTree standard-lib to write some xml. My output xml has no line breaks! So, it looks like that: instead of something like this: I'm aware of lxml which seems to have a pretty print option, but I would prefer to use the standard-lib ElementTree which seems not to have a feature like this. Do I miss something using the ElementTree-lib or is it bug? Neither, as far as I know. The XML you get is perfectly valid XML. If you want to pretty print it, there's a recipe here: http://effbot.org/zone/element-lib.htm#prettyprint, but I don't think it's been included in the standard library yet. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Elementtree and pretty printing in Python 2.7
On Fri, Aug 20, 2010 at 3:49 AM, Knacktus wrote: > Hi guys, > > I'm using Python 2.7 and the ElementTree standard-lib to write some xml. > > My output xml has no line breaks! So, it looks like that: > > > > instead of something like this: > > > > > > I'm aware of lxml which seems to have a pretty print option, but I would > prefer to use the standard-lib ElementTree which seems not to have a feature > like this. > > Do I miss something using the ElementTree-lib or is it bug? Neither, as far as I know. The XML you get is perfectly valid XML. If you want to pretty print it, there's a recipe here: http://effbot.org/zone/element-lib.htm#prettyprint, but I don't think it's been included in the standard library yet. -- Jerry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Elementtree and pretty printing in Python 2.7
Hi guys, I'm using Python 2.7 and the ElementTree standard-lib to write some xml. My output xml has no line breaks! So, it looks like that: instead of something like this: I'm aware of lxml which seems to have a pretty print option, but I would prefer to use the standard-lib ElementTree which seems not to have a feature like this. Do I miss something using the ElementTree-lib or is it bug? Cheers, Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor