开发者

XML to preserve the whitespace

开发者 https://www.devze.com 2023-03-10 11:43 出处:网络
<?xml version=\"1.0\"?> <para> <![CDATA[ gkjdfjg fdgsdfsdfdsf sdfdsfdsfsdfds fdsfdsfdsfsdfsd开发者_JS百科fd sdfsdf
<?xml version="1.0"?>
<para>
<![CDATA[
gkjdfjg fdgsdfsdfdsf sdfdsfdsfsdfds fdsfdsfdsfsdfsd开发者_JS百科fd 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


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

精彩评论

暂无评论...
验证码 换一张
取 消