XML DOM replaceData () method
Definition and Usage
replaceData () method replaces the data annotation node.
grammar
commentNode.replaceData(start,length,string)
参数 | 描述 |
---|---|
start | 必需。规定在何处替换字符。开始值以 0 开始。 |
length | 必需。规定替换多少个字符。 |
string | 必需。规定插入的字符串。 |
Examples
The following code fragment uses loadXMLDoc () to " books_comment.xml " into xmlDoc, and the "Simple" replacing the first <book> element comment node "Easy":
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].replaceData(4,6,"Easy");
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].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 some loops and if statements to execute only the processing nodes for comment. Node type comment node is eight.
Comment objects