Reputation: 11780
I want to produce an XML file where carriage return in elements are represented by the following sequence
but I'm unable get:
<elem>Hello world!</elem>
If I do the following:
var elem = new XElement("elem", "Hello\nworld!");
It produces:
<elem>Hello
world!</elem>
If I do the following:
var elem = new XElement("elem", "Hello world!");
It produces:
<elem>Hello&#13;world!</elem>
Any ideas?
Upvotes: 0
Views: 786
Reputation: 2214
Okay your answer is pretty clear. Anytime you need to write special chars into xml values, you would use CDATA.
Here's how you do it.
<elem><![CDATA[Hello world!]]></elem>
This is the fix you are looking for.
[UPDATE]
The only reason I stumbled on this answer initially, was because I was thinking about HTML. However, if you were writing this in HTML, you would simply use a <br />
tag.
Upvotes: 1