How to have line breaks in XML attributes?

2019-04-20 07:43发布

I have a attribute called: description and I want to have the following in it with new lines:

This is the content description section.
Download instruction:
This is the contents on how to download contents.
Hotline support:
This is the hotline for contents.

How do I create a new line for it in xml?

3条回答
\"骚年 ilove
2楼-- · 2019-04-20 08:28

If you need it in XML attribute, you'll have to use character entities:

<element attribute="First line&#10;Second line&#10;Third line..." />
查看更多
姐就是有狂的资本
3楼-- · 2019-04-20 08:35

Basically you want to insert CRLF:

CR code: &#13;
LF code: &#10;

<myelement description="line1&#13;&#10;line2&#13;&#10;line3"/>
查看更多
Anthone
4楼-- · 2019-04-20 08:35

Try it like this:

<description><![CDATA[first line<br />second line<br />]]></description> 

Basically you wrap the content within your tag inside "" for the closing tag, inbetween this tag you can use
to cause a line break. If you want to double space it, use two
like this:

Hope this helps.

查看更多
登录 后发表回答