XML DOM insertData() Method
Definition and Usage
The insertData() method inserts a string into the comment node.
Syntax:
commentNode.insertData(start,string)
Parameter | Description |
---|---|
start | Required. Specifies where to insert the character. This value starts from 0. |
string | Required. Specifies the string to be inserted. |
Description
This method inserts the specified string string Insert at specified position start The text of the Comment node is located here.
Example
The following code segment uses JavaScript functions loadXMLDoc() Load the XML file books_comment.xml Load xmlDoc and then insert a string into 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)
{
//Process only comment nodes
x[i].insertData(10,"Illustrated ");
document.write(x[i].data);
document.write("<br />");
}
}
The output of the above code:
(Book 6) (Illustrated Hardcover)
In this example, we use a loop and if statement to perform processing that is only for comment nodes. The node type of comment nodes is 8.
Try It Yourself (TIY)
Related Pages
XML DOM Reference Manual:CharacterData.insertData()