Re: [lxml-dev] etree not printing pretty :(
Martin Seiler, 19.11.2009 12:05:
I am rather new to python and lxml and I wonder about the output of my tree. I add an Element, which contains some childs to a tree. When I write the output everything is in pretty print, but the elements I appended. They show up in one line. did you read this?
http://codespeak.net/lxml/FAQ.html#why-doesn-t-the-pretty-print-option-refor...
Yes, I did and applied before. If I print out the Element before appending it, it works fine, just after appending it to an existing tree it shows this behavior.
libxml2 uses a heuristic to handle document-style content. When it finds tail text on an element, it switches to keeping text content intact within the respective subtree. That's likely the problem here. Setting the .tail property of each element to None should fix this, i.e. for el in root.iter(): el.tail = None
Also changing the call to:
et.ElementTree(element=eggs, parser=parser).write(xmlout, pretty_print=True)
doesn't help?
No. Setting a different parser here doesn't do anything (probably worth an exception...) Stefan
participants (1)
-
Stefan Behnel