CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup. The only delimiter that is recognized in a CDATA section is the "]]>" string that ends the CDATA section. CDATA sections cannot be nested. Their primary purpose is for including material such as XML fragments, without needing to escape all the delimiters.
CharacterData.data attribute holds the text that is
contained by the CDATA section. Note that this may contain characters that need to be escaped outside of CDATA sections and
that, depending on the character encoding ("charset") chosen for
serialization, it may be impossible to write out some characters as part
of a CDATA section.
CDATASection interface inherits from the
CharacterData interface through the
CDATASection nodes are not merged by use
normalize method of the
No lexical check is done on the content of a CDATA section and it is
therefore possible to have the character sequence
in the content, which is illegal in a CDATA section per section 2.7 of [XML 1.0]. The
presence of this character sequence must generate a fatal error during
serialization or the cdata section must be splitted before the
serialization (see also the parameter
Note: Because no markup is recognized within a
CDATASection, character numeric references cannot be used as
an escape mechanism when serializing. Therefore, action needs to be taken
when serializing a
CDATASection with a character encoding
where some of the contained characters cannot be represented. Failure to
do so would not produce well-formed XML.
Note: One potential solution in the serialization process is to end the CDATA section before the character, output the character using a character reference or entity reference, and open a new CDATA section for any further characters in the text node. Note, however, that some code conversion libraries at the time of writing do not return an error or exception when a character is missing from the encoding, making the task of ensuring that data is not corrupted on serialization more difficult.
See also the Document Object Model (DOM) Level 3 Core Specification.
Inherited Constant Summary
|short||ATTRIBUTE_NODE||The node is an
|short||CDATA_SECTION_NODE||The node is a
|short||COMMENT_NODE||The node is a
|short||DOCUMENT_FRAGMENT_NODE||The node is a
|short||DOCUMENT_NODE||The node is a
|short||DOCUMENT_POSITION_CONTAINED_BY||The node is contained by the reference node.|
|short||DOCUMENT_POSITION_CONTAINS||The node contains the reference node.|
|short||DOCUMENT_POSITION_DISCONNECTED||The two nodes are disconnected.|
|short||DOCUMENT_POSITION_FOLLOWING||The node follows the reference node.|
|short||DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC||The determination of preceding versus following is implementation-specific.|
|short||DOCUMENT_POSITION_PRECEDING||The second node precedes the reference node.|
|short||DOCUMENT_TYPE_NODE||The node is a
|short||ELEMENT_NODE||The node is an
|short||ENTITY_NODE||The node is an
|short||ENTITY_REFERENCE_NODE||The node is an
|short||NOTATION_NODE||The node is a
|short||PROCESSING_INSTRUCTION_NODE||The node is a
|short||TEXT_NODE||The node is a
Inherited Method Summary
Returns all text of
Breaks this node into two nodes at the specified
deleteData(int offset, int count)
Remove a range of 16-bit units from the node.
The character data of the node that implements this interface.
The number of 16-bit units that are available through
substringData(int offset, int count)
Extracts a range of data from the node.
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
The absolute base URI of this node or
The first child of this node.
The last child of this node.
Returns the local part of the qualified name of this node.
The namespace URI of this node, or
The node immediately following this node.