我一直在尝试在XML中的代码中添加新的换行符,但一直没有成功.
我到目前为止尝试过:
<br />
<br>


Run Code Online (Sandbox Code Playgroud)
以下是我正在使用的代码示例.我在其中添加了" 
"以显示代码中的中断位置.
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
<item>
<summary>Tootsie roll tiramisu macaroon wafer carrot cake.

 Danish topping sugar plum tart bonbon caramels cake.
</summary>
</item>
Run Code Online (Sandbox Code Playgroud)
art*_*hur 86
新行XML
用XML

 
或尝试用CDATA提出的@dj_segfault(见他的回答);
<![CDATA[Tootsie roll tiramisu macaroon wafer carrot cake.
Danish topping sugar plum tart bonbon caramels cake.]]>
Run Code Online (Sandbox Code Playgroud)
Mic*_*Kay 39
你不需要任何花哨的东西:下面包含一个新行(实际上是两行):
<summary>Tootsie roll tiramisu macaroon wafer carrot cake.
Danish topping sugar plum tart bonbon caramels cake.
</summary>
Run Code Online (Sandbox Code Playgroud)
问题是,为什么这个换行符不会产生预期的效果:这是一个关于XML的接收者实际使用它的问题.例如,如果收件人将其翻译为HTML并且HTML正在浏览器中显示,则新行将由浏览器转换为空格.您需要告诉我们有关处理管道的信息.
Cou*_*dan 37
这个问题的解决方案是:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
<item>
<summary>
<![CDATA[Tootsie roll tiramisu macaroon wafer carrot cake. <br />
Danish topping sugar plum tart bonbon caramels cake.]]>
</summary>
</item>
Run Code Online (Sandbox Code Playgroud)
通过添加 <br />内部,<![CDATA]]>这允许线断开,从而创建一个新的线!
ST3*_*ST3 10
您可能正在使用Windows,因此新行是CR + LF(回车+换行).所以解决方案是:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
<item>
<summary>Tootsie roll tiramisu macaroon wafer carrot cake. Danish topping sugar plum tart bonbon caramels cake.
</summary>
</item>
Run Code Online (Sandbox Code Playgroud)
对于Linux,仅LF适用于Mac OS CR.
有问题的是显示Linux方式.
这个解决方案对我有用:
<summary>Tootsie roll tiramisu macaroon wafer carrot cake. 
Danish topping sugar plum tart bonbon caramels cake.</summary>
Run Code Online (Sandbox Code Playgroud)
您将有两行文字.
这对我使用XmlReader.Read方法很有用.
您可能需要将其放入CDATA 块中以保留空格
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="dummy.xsl"?>
<item>
<summary>
<![CDATA[Tootsie roll tiramisu macaroon wafer carrot cake.
Danish topping sugar plum tart bonbon caramels cake.]]>
</summary>
</item>
Run Code Online (Sandbox Code Playgroud)