XML Carriage return encoding

user273502 picture user273502 · Feb 15, 2010 · Viewed 144.9k times · Source

I was looking to represent a carriage return within an xml node.
I have tried a whitespace preserve, hex entity with no luck- and a \n. viewing via a browser.

Example

<Quote>
Alas, poor Yorick!
I knew him
</Quote>

Thanks.

Answer

Lachlan Roche picture Lachlan Roche · Feb 15, 2010

To insert a CR into XML, you need to use its character entity &#13;.

This is because compliant XML parsers must, before parsing, translate CRLF and any CR not followed by a LF to a single LF. This behavior is defined in the End-of-Line handling section of the XML 1.0 specification.