CDATA Sections
A CDATA section is a convenience used in XML documents that allows you to include literal text in element content without having to use < and & entity references to escape less-than and ampersand symbols, respectively. CDATA sections
are not a separate kind of node; they are not represented in the XQuery data model at all.
CDATA sections are delimited by <![CDATA[ and ]]>. Example 21-12 shows two h1 elements. The first element has a CDATA section that contains some literal text, including an unescaped ampersand character. It also contains a reference to a <catalog> element that is intended to be taken as a string, not as an XML element in the document. If this text were not enclosed in a CDATA section, the XML element would not be well formed. The second h1 element shown in the example is equivalent, using predefined entities to escape the ampersand and less-than characters.
Example 21-12. Two equivalent h1 elements, one with a CDATA section
<h1><![CDATA[Catalog & Price List from <catalog>]]></h1> <h1>Catalog & Price List from <catalog></h1>
When your query accesses an XML document that contains a CDATA section, the CDATA section is not retained. If the h1 element in Example 21-12 is queried, its content is Product Catalog & Price List from <catalog>. There is no way for the query processor to know that a CDATA section was used in the input document.
For convenience, CDATA sections can also be specified in a query, in the character data content of an ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access