I have been trying to add a new line/break to code within XML and have been unsuccessful.
I have tried so far:
<br />
<br>


Here is a sample of the code I am working with. I included "

" to show where the break is located within the code.
<?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>
It's generally considered bad practice to rely on linebreaks, since it's a fragile way to differentiate data. While most XML processors will preserve any whitespace you put in your XML, it's not guaranteed.
You can use 
 for line feed (LF) or 
 for carriage return (CR), and an XML parser will replace it with the respective character when handing off the parsed text to an application.
No. New line characters are perfectly acceptable in XML. They are included in the character range for text.
Adding line breaks in your HTML using the <br> tag is a simple way to make your text more readable. The <br> tag will insert a line break wherever you put it within your code.
New Line XML
with XML



or try like @dj_segfault proposed (see his answer) with CDATA;
<![CDATA[Tootsie roll tiramisu macaroon wafer carrot cake.
Danish topping sugar plum tart bonbon caramels cake.]]>
The solution to this question is:
<?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>
by adding the <br />
inside the the <![CDATA]]>
this allows the line to break, thus creating a new line!
You don't need anything fancy: the following contains a new line (two, actually):
<summary>Tootsie roll tiramisu macaroon wafer carrot cake.
Danish topping sugar plum tart bonbon caramels cake.
</summary>
The question is, why isn't this newline having the desired effect: and that's a question about what the recipient of the XML is actually doing with it. For example, if the recipient is translating it to HTML and the HTML is being displayed in the browser, then the newline will be converted to a space by the browser. You need to tell us something about the processing pipeline.
You are probably using Windows, so new line is CR + LF
(carriage return + line feed). So solution would be:
<?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>
For Linux there is only LF
and for Mac OS only CR
.
In question there showed Linux way.
This solution worked to me:
<summary>Tootsie roll tiramisu macaroon wafer carrot cake. 
Danish topping sugar plum tart bonbon caramels cake.</summary>
You will have the text in two lines.
This worked to me using the XmlReader.Read method.
You probably need to put it in a CDATA block to preserve whitespace
<?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>
Without using CDATA, try
<xsl:value-of select="'
'" />
Note the double and single quotes.
That is particularly useful if you are not creating xml
aka text. <xsl:output method="text" />
The easiest way to give a line break is to do the following :
1> Add the following in CSS - e{display:block}
2> Now wherever you want to give a line break, type -
<e></e>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With