XML DOM createComment() Method
Document Object
Definition and Usage
The createComment() method creates a comment node.
This method returns a Comment object.
Syntax
createComment(data)
| Parameters | Description |
|---|---|
| data | A string that specifies the data for the node. |
Example
The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc, and add the comment node to
Example
xmlDoc
=
loadXMLDoc
(
"
books.xml
"
)
;
x
=
xmlDoc
.
getElementsByTagName
(
'
book
'
)
;
for
(
i
=
0
;
i
<
x
.
length
;
i
++
)
{
newComment
=
xmlDoc
.
createComment
(
"
Revised April 2008
"
)
;
x
[
i
]
.
appendChild
(
newComment
)
;
}
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