Adding a new line/break tag in XML

Xml

Xml Problem Overview


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.       
               &#xA; Danish topping sugar plum tart bonbon caramels cake.
     </summary>
  </item>

Xml Solutions


Solution 1 - Xml

New Line XML

with XML

  1. Carriage return: &#xD;
  2. Line feed: &#xA;

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.]]>

Solution 2 - Xml

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!

Solution 3 - Xml

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.

Solution 4 - Xml

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.&#13;&#10;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.

Solution 5 - Xml

This solution worked to me:

<summary>Tootsie roll tiramisu macaroon wafer carrot cake. &#xD;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.

Solution 6 - Xml

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> 

Solution 7 - Xml

Without using CDATA, try

<xsl:value-of select="'&#xA;'" />

Note the double and single quotes.

That is particularly useful if you are not creating xml aka text. <xsl:output method="text" />

Solution 8 - Xml

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>

Solution 9 - Xml

The Way to do Line Break in XML is to use &#xA;

It worked for me in Eclipse IDE , when I was designing my XML layout & was using TextView.

Solution 10 - Xml

Had same issue when I had to develop a fixed length field format.

Usually we do not use line separator for binary files but For some reason our customer wished to add a line break as separator between records. They set

< record_delimiter value="\n"/ >

but this didn't work as records got two additional characters:
< record1 > \n < record2 > \n.... and so on.

Did following change and it just worked.

< record_delimiter value="\n"/> => < record_delimiter value=" "/ >

After unmarshaling Java interprets as new line character.

Solution 11 - Xml

Wanted to add my solution:

&lt; br/ &gt;

which is basically the same as was suggested above
In my case I had to use &lt for < and &gt for > Simply putting <br /> did not work.

Solution 12 - Xml

just simply press enter it make a break

<![CDATA[this is
my text.]]>

Solution 13 - Xml

This can be addressed simple by CSS attribute:

XML: <label name="pageTac"> Hello how are you doing? Thank you I'm Good</label>

CSS

.pageText{
white-space:pre !important; // this wraps the xml text.}

HTML / XSL

<tr>
		<td class="pageText"><xsl:value-of select="$Dictionary/infolabels/label[@name='pageTac']" />
			</td></tr>

Solution 14 - Xml

(Using system.IO)

You can simply use \n for newline and \t in front of the string to indent it.

For example in c#:

public string theXML() {
    string xml = "";
    xml += "<Scene>\n";
    xml += "\t<Character>\n";

   
    xml += "\t</Character>\n";
    xml += "</Scene>\n";
    return xml;
}

This will result in the output: http://prntscr.com/96dfqc

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCourtney JordanView Question on Stackoverflow
Solution 1 - XmlarthurView Answer on Stackoverflow
Solution 2 - XmlCourtney JordanView Answer on Stackoverflow
Solution 3 - XmlMichael KayView Answer on Stackoverflow
Solution 4 - XmlST3View Answer on Stackoverflow
Solution 5 - Xmlmerce_00View Answer on Stackoverflow
Solution 6 - Xmldj_segfaultView Answer on Stackoverflow
Solution 7 - XmlGabe RainbowView Answer on Stackoverflow
Solution 8 - XmlYash KulkarniView Answer on Stackoverflow
Solution 9 - XmlRohan MundheyView Answer on Stackoverflow
Solution 10 - XmlaprodanView Answer on Stackoverflow
Solution 11 - XmlAlex ChastukhinView Answer on Stackoverflow
Solution 12 - XmlZakiye MView Answer on Stackoverflow
Solution 13 - XmlZabi BaigView Answer on Stackoverflow
Solution 14 - XmlShend IbraniView Answer on Stackoverflow