user269867
user269867

Reputation: 3942

XML to preserve the whitespace

<?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

Upvotes: 1

Views: 5200

Answers (1)

Niels
Niels

Reputation: 1330

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

Upvotes: 1

Related Questions