XML DOM deleteData () method
Definition and Usage
deleteData () method deletes data from the comment node.
grammar
commentNode.deleteData(start,length)
参数 | 描述 |
---|---|
start | 必需。规定从何处开始删除数据。开始值以 0 开始。 |
length | 必需。规定删除多少个字符。 |
Examples
The following code fragment uses loadXMLDoc () to " books_comment.xml " into xmlDoc and remove some characters from the first node in a comment:
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].deleteData(0,33);
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].deleteData(0,33);
document.write(x[i].data);
document.write("
");
}
}
Output:
(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