XML DOM substringData() Method

Definition and Usage

The substringData() method retrieves data from a text node.

Syntax:

substringData(start,length)
Parameters Description
start Required. From where to extract characters. The starting value is 0.
length Required. Specify how many characters to extract.

Example

In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().

The following code snippet retrieves a fragment from the text node of the first <title> element in "books.xml" and outputs it:

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
y=x.substringData(9,7);
document.write(x.nodeValue);
document.write("<br />");
document.write(y);

Output:

Everyday Italian
Italian

Related pages

XML DOM reference manual:CharacterData.substringData()