Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have line breaks in XML attributes?

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?

like image 285
sling Avatar asked Dec 01 '09 04:12

sling


People also ask

How do I add a line break in XML?

use <br/> ; or. wrap block in an element such as a div or p which by default causes a line break after the enclosed text, or in an element such as pre which by default typically will preserve whitespace and line breaks; or.

Can XML have line breaks?

XML does not require a specific form of line break, so you can use whatever is convenient (carriage return, linefeed, or a combination) when creating an XML file. XML parsers will do the right thing largely because they're parsing on tags, not records - so whatever line break you're using is just whitespace to XML.

Can XML attribute values have spaces?

A simple attribute value, even that of an xsl:param element's name attribute, may contain whitespace and be perfectly well-formed as XML .

What is separator in XML?

For splitting the value, which should be done with a programming language ideally (even if XPath and XSLT do provide functions), white space seems like a natural separator in XML, but CSS uses a semicolon, and another common separator is a comma, though neither is nearly as XML-friendly as white space since the W3C XML ...


2 Answers

Basically you want to insert CRLF:

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

<myelement description="line1&#13;&#10;line2&#13;&#10;line3"/>
like image 121
Ramesh Soni Avatar answered Oct 30 '22 16:10

Ramesh Soni


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

<element attribute="First line&#10;Second line&#10;Third line..." />
like image 33
Pavel Minaev Avatar answered Oct 30 '22 17:10

Pavel Minaev