Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM substringData() Method

XML DOM substringData() Method


Comment Object Reference Comment Object


Definition and Usage

The substringData() method gets a string from a comment node.

Syntax

substringData(start,length)

Parameters Description
start Required. Specifies where to start extracting characters. The starting value begins at 0.
length Required. Specifies how many characters to extract.

Example

The following code snippet uses loadXMLDoc() to load "books_comment.xml" Load into xmlDoc, and get the "(Hardcover)" string from the first comment element:

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

y=x[i].substringData(33,11);

document.write(y);

document.write("

");

}

}

Output:

(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 Reference Comment Object