Latest web development tutorials

XML DOM substringData () method

Comment Object Reference Comment objects

Definition and Usage

substringData () method to get a string from the comment node.

grammar

substringData(start,length)

参数 描述
start 必需。规定从何处开始提取字符。开始值以 0 开始。
length 必需。规定提取多少字符。


Examples

The following code fragment uses loadXMLDoc () to " books_comment.xml " into xmlDoc and obtain "(Hardcover)" string from the first annotation element:

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
y=x[i].substringData(33,11);
document.write(y);
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 Object Reference Comment objects