CDATASection (W3C DOM Core object)
| Version | Depr. | Parent |
|---|---|---|
| DOM1 | No | Text |
| IE5.5+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Partial | Full | Full | Full |
Example
<description> <![CDATA[ <p>Good relations have I with the Wookies</p> ]]> </description>
The example above shows a block of
CDATA, enclosing serialized HTML, within an RSS
<description> element.
Description
The
CDATASection interface inherits from CharacterData through Text, and
represents a CDATA section in XML.
CDATA sections are used to escape blocks of text that
would otherwise be treated as markup. In web development they're often
used for including unpredictable HTML inside another form of XML, or for
programmatic code like scripts and style information.
A
CDATASection node cannot have children.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 1.5 | 2.0 | 3.0 | 1.3 | 2.0 | 3.0 | 9.0 | 9.5 |
| Partial | Partial | Partial | Full | Full | Full | Full | Full | Full | Full | Full |
Internet Explorer 6 and 7 in XML do not inherit
the normalize method from Node.
Since CDATA is an XML construct, it's only
reasonable to judge its behavior in terms of XML (either on HTML pages
in XHTML mode1, or pure XML). The
behavioral variations of browsers in HTML mode2 are documented
here for interest and reference, but the support summary table above
does not consider this behavior (ie. if the interface works fully in
XML then it's considered to be fully supported, with no notes).
Internet Explorer in HTML doesn't
implement the CDATASection interface — it cannot
see the delimiters, nor any plain text content; if there's HTML inside
the CDATA section, Internet Explorer will see the
HTML as markup — a collection of childNodes
that begins with either a Text node with the value
DATA[3 (for IE6 and IE7), or an Element
node with the name ! (in IE5.5), and ends with a
Text node with the value
]]>.
Firefox in HTML mode treats
CDATA sections like comments — it returns a Comment node, whose data begins with
[CDATA[ and ends with ]].
Safari in HTML mode doesn't implement
the CDATASection interface — it cannot see the
delimeters, nor any plain text content; if there's HTML inside the
CDATA section, Safari will see the HTML as markup —
a collection of childNodes that ends with a
Text node having the value
]]>.
Opera in HTML mode treats
CDATA sections exactly as it does in XML, unless
they contain script or style information, in which case it treats them
like Text (that include the full
CDATA delimiters as part of the text).