XML DOM createCDATASection() Method
Document Object
Definition and Usage
The createCDATASection() method creates a CDATA section node.
This method returns a CDATASection object.
Syntax
createCDATASection(data)
| Parameters | Description |
|---|---|
| data | A string that specifies the data for the node. |
Example
The following code snippet uses loadXMLDoc() to load "books.xml" Load into xmlDoc, and add a CDATA section node to the
Example
xmlDoc
=
loadXMLDoc
(
"
books.xml
"
)
;
x
=
xmlDoc
.
getElementsByTagName
(
"
book
"
)
;
newtext
=
"
Special Offer & Book Sale
"
;
for
(
i
=
0
;
i
<
x
.
length
;
i
++
)
{
newCDATA
=
xmlDoc
.
createCDATASection
(
newtext
)
;
x
[
i
]
.
appendChild
(
newCDATA
)
;
}
for
(
i
=
0
;
i
<
x
.
length
;
i
++
)
{
document
.
write
(
x
[
i
]
.
getElementsByTagName
(
"
title
"
)
[
0
]
.
childNodes
[
0
]
.
nodeValue
)
;
document
.
write
(
"
"
)
;
document
.
write
(
x
[
i
]
.
lastChild
.
nodeValue
)
;
document
.
write
(
"
"
)
;
}
Try it »
Document Object