1
<?xml version="1.0"?>
<para>
<![CDATA[
gkjdfjg fdgsdfsdfdsf sdfdsfdsfsdfds fdsfdsfdsfsdfsdfd sdfsdf
sadf sdff sdf sdf

gkjdfjg fdgsdfsdfdsf sdfdsfdsfsdfds fdsfdsfdsfsdfsdfd sdfsdf
sadf sdff sdf sdf
]]>

</para>

I save this file as text.xml and try to view in browser. This return all text in one line !!! It is not preserving the content as defined in CDATA section ?.

I had read somewhere that XML preserve the white space then why it is not preserving the even if defined under CDATA section ?

Thanks

user269867
  • 3,266
  • 9
  • 45
  • 65
  • Where did you read *"that XML preserve the white space"*? What I know from top of my head is that this is much more differentiated (compare http://www.w3.org/TR/REC-xml/#sec-line-ends). Also take care that the XML display in your browser might count as an application which therefore must not follow the rules of the XML standard, as the XML is already processed by the application for display purposes. – hakre Jul 06 '14 at 16:49

1 Answers1

1

The browser displays it all on one line because browsers ignore whitespace. That is why you use <br /> tags (and others) in html to put in enters and white spaces.

So if you want to have a white line try this:

<?xml version="1.0"?>
<para>
<![CDATA[
gkjdfjg fdgsdfsdfdsf sdfdsfdsfsdfds fdsfdsfdsfsdfsdfd sdfsdf
sadf sdff sdf sdf
<br /><br />
gkjdfjg fdgsdfsdfdsf sdfdsfdsfsdfds fdsfdsfdsfsdfsdfd sdfsdf
sadf sdff sdf sdf
]]>
Niels
  • 1,340
  • 2
  • 15
  • 32
  • 1
    Adding
    do not resolve my concern. It shows
    in the XML content
    – user269867 Jun 06 '11 at 10:56
  • when i try your original code in IE it does keep the whitespace. Jon's solution seems the [official way](http://msdn.microsoft.com/en-us/library/ms256097.aspx) to do it, but doesn't work in my FF either. I guess it is different per browser. What do you want to use it in? – Niels Jun 06 '11 at 11:05
  • Yes in IE it preserve but not in FF. Example to demo that XML preserves the white space.Any reason FF is not displaying as per expectation. – user269867 Jun 06 '11 at 11:16
  • I can't find the reason why firefox doesn't show the whitespace. But what exactly do you want to use this for? – Niels Jun 06 '11 at 11:34
  • creating an example to demo that XML preserves the white space – user269867 Jun 06 '11 at 11:42