XML DOM appendData() Method

Definition and Usage

The appendData() method adds the specified text to the end of the text contained in the comment node.

Syntax:

commentNode.appendData(string)
Parameter description
string The string to be appended to the comment node.

description

This method takes a string string Append to the end of the data attribute of the node.

Example

The following code snippet uses JavaScript functions loadXMLDoc() Load the XML file books_comment.xml Load xmlDoc and append text to the first comment node:

xmlDoc=loadXMLDoc("books_comment.xml");
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{ 
if (x[i].nodeType==8)
  { 
  //Only process comment nodes
  x[i].appendData(" Special Offer");
  document.write(x[i].data);
  document.write("<br />");
  } 
}

Output of the above code:

(Book 6) (Hardcover) Special Offer

In this example, we use a loop and if statement to perform processing that targets only comment nodes. The node type of comment nodes is 8.

Related Pages

XML DOM Reference Manual:CharacterData.appendData()