XML DOM replaceData() Method
Comment Object
Definition and Usage
The replaceData() method replaces data in a comment node.
Syntax
commentNode.replaceData(start,length,string)
| Parameters | Description |
|---|---|
| start | Required. Specifies where to replace characters. The starting value begins at 0. |
| length | Required. Specifies how many characters to replace. |
| string | Required. Specifies the string to insert. |
Example
The following code snippet uses loadXMLDoc() to load "books_comment.xml" Load into xmlDoc, and replace "Simple" with "Easy" in the comment node of the first
Example
xmlDoc=loadXMLDoc("books_comment.xml");
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i { if (x[i].nodeType==8) { //Process only comment nodes x[i].replaceData(4,6,"Easy"); document.write(x[i].data); document.write(" "); } } Output: 125 Easy and Delicious Recipes (Hardcover) Try it » In the example above, we use a loop and an if statement to perform processing only on comment nodes. The node type of a comment node is 8.
Comment Object