Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM createCDATASection() Method

XML DOM createCDATASection() Method


Document Object Reference 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 element:

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 Reference Document Object