XML and newlines

Martin v. Loewis martin at v.loewis.de
Sat Feb 16 16:26:24 EST 2002


Hans Nowak <wurmy at earthlink.net> writes:

> It was part of a previous problem; the XML supposedly only contained \n,
> where \r\n was desirable. While investigating it, I stumbled upon a
> different, more serious problem-- no newlines at all.

This is all intentional. In content, the XML processor *must*
normalize newline characters, replacing different variants of newline
with #xA. In *attribute* only, newline is further normalized to space
characters.  So if you have content where newline characters are
relevant, don't put that into attributes. If you have data which are
that sensible to their binary representation, you may consider not
using XML at all, or chosing a binary-safe representation, such as
base64-encoded strings.

Regards,
Martin



More information about the Python-list mailing list