[lxml-dev] Whitespace foiling pretty_print - any fix?

f an XML element has whitespace along with sub elements, pretty_print does not work well. This is probably a XML whitespace issue, but is there any way to work around this issue? Here's example code and the output it prints, and what I would like to get: from lxml import etree as ET root = ET.XML("""<a> <b>test</b> </a>""") ET.SubElement(root, "c") ET.SubElement(root, "d") print ET.tostring(root, pretty_print=True) # This prints: """<a> <b>test</b> <c/><d/></a> """ # Would like: """<a> <b>test</b> <c/> <d/> </a> """

B Wooster wrote:
f an XML element has whitespace along with sub elements, pretty_print does not work well.
This is probably a XML whitespace issue, but is there any way to work around this issue?
Here's example code and the output it prints, and what I would like to get:
from lxml import etree as ET root = ET.XML("""<a> <b>test</b> </a>""") ET.SubElement(root, "c") ET.SubElement(root, "d") print ET.tostring(root, pretty_print=True) # This prints: """<a> <b>test</b> <c/><d/></a> """ # Would like: """<a> <b>test</b> <c/> <d/> </a> """
http://codespeak.net/lxml/FAQ.html#why-doesn-t-the-pretty-print-option-refor... Stefan
participants (2)
-
B Wooster
-
Stefan Behnel