![]() (I suspect all the comparisons to comments are kinda misleading/unhelpful.) Finally, even if the data only contains a few special characters but the data is very very long (the text of a chapter, say), it's nice to not have to be en/de-coding those few entities as you edit your xml file. As mentioned, other common uses include when you're embedding URLs that contain ampersands. Print( 'Still working, 'zzz'.' ) Įspecially if you are copy/pasting this code from a file (or including it, in a pre-processor), it's nice to just have the characters you want in your xml file, w/o confusing them with XML tags/attributes. In that situation your data includes a big chunk of characters that include '&' and ' One big use-case: your xml includes a program, as data (e.g. This DOM manipulation code will either throw an exception (in Firefox) or result in a poorly structured XML document: MyEl.appendChild(xmlDoc.createCDATASection("This section cannot contain ]]>")) Likewise, from a DOM manipulation perspective you can't create a CDATA section which includes ]]>: var myEl = xmlDoc.getElementById("cdata-wrapper") Any character data which contains ]]> will have to - as far as I know - be a text node instead. Something to take note of with CDATA sections is that they have no encoding, so there's no way to include the string ]]> in them. html) and open it using FireFox ( not Internet Explorer) to see the difference between the comment and the CDATA section the comment won't appear when you look at the document in a browser, while the CDATA section will: Syntactically, it behaves similarly to a comment: This means given these four snippets of XML from one well-formed document: Ī CDATA section is " a section of element content that is marked for the parser to interpret as only character data, not markup." Parameter Entity references are not recognized inside of comments.In CDATA you cannot include the string ]]> ( CDEnd), while in a comment - is invalid.As Richard points out, CDATA is still part of the document, while a comment is not. ![]() The key differences between CDATA and comments are: CDATA stands for Character Data and it means that the data in between these strings includes data that could be interpreted as XML markup, but should not be.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |