简体   繁体   English

XElement中的回车

[英]Carriage return in XElement

I want to produce an XML file where carriage return in elements are represented by the following sequence 
 我想生成一个XML文件,其中元素中的回车由以下序列
表示
 but I'm unable get: 但我无法获得:

<elem>Hello&#13;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&#13;world!");

It produces: 它产生:

<elem>Hello&amp;#13;world!</elem>

Any ideas? 有任何想法吗?

Okay your answer is pretty clear. 好的,答案很清楚。 Anytime you need to write special chars into xml values, you would use CDATA. 每当您需要将特殊字符写入xml值时,都将使用CDATA。

Here's how you do it. 这是您的操作方式。

<elem><![CDATA[Hello&#13;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. [更新]我最初偶然发现此答案的唯一原因是因为我在考虑HTML。 However, if you were writing this in HTML, you would simply use a <br /> tag. 但是,如果您使用HTML编写此代码,则只需使用<br />标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM