Preserving whitespace during lxml serialization
09:43 15 Sep 2026

is there a way to retain whitespaces when serializing an etree.Element with lxml?

E.g.:


turns into:


which is not the desired behaviour.

With xml.Etree this works (I guess because of this short_empty_elements=True), but I have to use lxml.

python serialization lxml