[lxml-dev] pretty_print with tail

Hi, A test example prints: <emission><color><red>0.231</red>kFloat<green>0.326</green>kFloat<blue>0.921</blue>kFloat</color>kColor</emission> I am using: etree.tostring(root, method="xml", pretty_print=True) May be because every element/children has a tail text. Is it possible to format the output in this way: <emission> <color> <red>0.231</red>kFloat <green>0.326</green>kFloat <blue>0.921</blue>kFloat </color>kColor </emission> Thanks Prashant Python 2.6.2 lxml 2.2.4 wxPython 2.8.10.1 XP 32 The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

Prashant Saxena, 23.01.2010 16:20:
A test example prints: <emission><color><red>0.231</red>kFloat<green>0.326</green>kFloat<blue>0.921</blue>kFloat</color>kColor</emission>
I am using: etree.tostring(root, method="xml", pretty_print=True)
May be because every element/children has a tail text.
Is it possible to format the output in this way:
<emission> <color> <red>0.231</red>kFloat <green>0.326</green>kFloat <blue>0.921</blue>kFloat </color>kColor </emission>
http://codespeak.net/lxml/FAQ.html#why-doesn-t-the-pretty-print-option-refor... Stefan

Prashant Saxena, 23.01.2010 16:20:
A test example prints: <emission><color><red>0.231</red>kFloat<green>0.326</green>kFloat<blue>0.921</blue>kFloat</color>kColor</emission>
I am using: etree.tostring(root, method="xml", pretty_print=True)
May be because every element/children has a tail text.
Is it possible to format the output in this way:
<emission> <color> <red>0.231</red>kFloat <green>0.326</green>kFloat <blue>0.921</blue>kFloat </color>kColor </emission>
http://codespeak.net/lxml/FAQ.html#why-doesn-t-the-pretty-print-option-refor... Parsing a xml file from disk which has written as above is not a problem and output is as is. I am interested in writing it to disk as above. from lxml import etree root = etree.Element("emmision") color = etree.SubElement(root, "color") color.tail = "kColor" red = etree.SubElement(color, "red") green = etree.SubElement(color, "green") blue = etree.SubElement(color, "blue") red.text = "0.231" green.text = "0.326" blue.text = "0.291" red.tail = "kFloat" green.tail = "kFloat" blue.tail = "kFloat" print etree.tostring(root, method="xml", pretty_print=True) This code prints every thing in a single line & it's hard to read. Do I have to write a custom function to parse the string and print as needed? Prashant Python 2.6.2 lxml 2.2.4 The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

Prashant Saxena, 23.01.2010 18:56:
Prashant Saxena, 23.01.2010 16:20:
A test example prints: <emission><color><red>0.231</red>kFloat<green>0.326</green>kFloat<blue>0.921</blue>kFloat</color>kColor</emission>
I am using: etree.tostring(root, method="xml", pretty_print=True)
May be because every element/children has a tail text.
Is it possible to format the output in this way:
<emission> <color> <red>0.231</red>kFloat <green>0.326</green>kFloat <blue>0.921</blue>kFloat </color>kColor </emission>
http://codespeak.net/lxml/FAQ.html#why-doesn-t-the-pretty-print-option-refor... [...] This code prints every thing in a single line & it's hard to read. Do I have to write a custom function to parse the string and print as needed?
See the last paragraph of the section I linked above. Stefan
participants (2)
-
Prashant Saxena
-
Stefan Behnel