Is there any use for putting a string that contains enters (char 10 or 13) in a xml CDATA section?

I know it sounds obvious, but if you are embedding a plain ascii text file and you want to preserve the manual formatting of the file verbatim. That would be a useful case Other cases that I have encountered are outputting metadata from images and I have no control over their formatting.

I know it sounds obvious, but if you are embedding a plain ascii text file and you want to preserve the manual formatting of the file verbatim. That would be a useful case. Other cases that I have encountered are outputting metadata from images and I have no control over their formatting.

In XML, CDATA preserves whitespace, ordinary text does not.

I could be way off base on this, but I seem to remember it being a good recommendation to put Javascript code inside CDATA tags. In fact see the selected answer for this stack overflow question as it does a decent job on answering why: stackoverflow.com/questions/66837/javasc....

Clearly not using javascript here so I don't see how that's relevant – Jonathan Fingland May 29 '09 at 9:17 Yup, now that you mention it, whenever I write XHTML I always put javascript and css in CDATA tags - it just makes your life easier when you need to use ampersands freely. – Elijah May 29 '09 at 9:18 It's not javascript, but basic text. – plep May 29 '09 at 9:23 The original poster didn't define whether it was javascript or not.My answer simply dictates when it would be advisable to put a "string" with CR\LFs in a CDATA tag.

– Jordan S. Jones May 29 '09 at 9:29.

I would say it depends entirely on whether your XML parse strips whitespace and control characters. I'm fairly certain the System. Xml ones in .

NET don't, nor MSXML or Xerces but there are options to do it.

Ok. In my testcase I used root.getNodeValue() to retrieve the string. So it depends on the xml implementation I use if I would get "mytext\n\n\n" back or "mytext"!?

I hope this stripping of whitespace is not the default. I'll go check. – plep May 29 '09 at 9:29 In .

Net, there are properites in the Xml readers that control whitespace preservation (e.g. XmlDocument. PreserveWhitespace) – Jason Williams Oct 11 '09 at 17:50.

Putting text inside a CDATA section should ensure that any parser ignores it, so the code above might be used to ensure correct formatting regardless what a parser is told to do with whitespace. I supposed that it effectively says that the line breaks are meaningful in that section, and not just incidental. Not sure why you would only put a CDATA section in if there were linebreaks present though, so I would guess it's just a workaround rather than a by-design thing in the code given.

I suspect a work-around too, but unfortunatly, the code commit doesn't document why this is written the way it is (whats new :-) ). So I hoped that somebody would recognize a similar case. – plep May 29 '09 at 9:34.

Since CDATA sections allow you to put arbitrary data inside an XML document without having to understand anything about how the XML objects are going to handle it, they're frequently used by people who don't understand how the XML objects work. Generally speaking, when I see someone creating CDATA in their XML I start from the assumption that they don't really know what they're doing unless they've included a good explanation. (And more often than not, that good explanation reveals that they didn't know what they were doing.) The original developer is probably confusing the DOM's handling of text nodes that contain whitespace with its handling of text nodes that contain only whitespace.

DOMs frequently normalize whitespace-only text nodes, which can be a problem in XML like: If the DOM normalizes the four spaces in that second element down to one space, that changes the functionality of that transform, which is an unambiguously bad thing. But there's a reason you don't see XSLT that looks like this: /xsl:text> And that's that XSLT processors are written by people who understand how the XML objects work, and who know that in their specific case, it's important to tell the DOM to preserve whitespace in whitespace-only text nodes.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions