[lxml-dev] Question about newlines

Stefan Behnel stefan_ml at behnel.de
Fri Dec 14 09:25:43 CET 2007


Stefan Behnel wrote:
> Noah Slater wrote:
>> On Sun, Dec 09, 2007 at 08:48:17AM +0100, Stefan Behnel wrote:
>>> Serialisation will never alter content.
>> [snip]
>>>>   1) When adding a PI via the element.addprevious method and PI has
>>>>      it's tail trimmed and so when serialising the PI runs into the
>>>>      root element.
>> Well, this is well and good but lxml REMOVES the PI tail so I cannot
>> insert a newline even if I want to.
> 
> Ah, got it. Thanks for insisting. :)
> 
> So the behaviour
> for the root level would be: drop all whitespace when parsing, and add line
> breaks around PIs and comments on serialisation.

..., but only if pretty printing is requested. I think that's all that's
needed here.

Stefan



More information about the lxml-dev mailing list