XML DOM appendData () method
Definition and Usage
appendData () method to add data to the end of the comment node.
grammar
commentNode.appedData(string)
参数 | 描述 |
---|---|
string | 必需。向注释节点添加的字符串。 |
Examples
The following code fragment uses loadXMLDoc () to " books_comment.xml " into xmlDoc additional element to the first comment text:
Examples
xmlDoc=loadXMLDoc("books_comment.xml");
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
x[i].appendData(" Special Offer");
document.write(x[i].data);
document.write("
");
}
}
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
x[i].appendData(" Special Offer");
document.write(x[i].data);
document.write("
");
}
}
Output:
125 Simple and Delicious Recipes (Hardcover) Special Offer
try it"
In the example above, we use some loops and if statements to execute only the processing nodes for comment. Node type comment node is eight.
Comment objects