This method splits a Text node into two at the specified offset. It places all the characters from the offset to the end of the string into a new Text node that immediately follows this one.
This method returns the new Text node.
XML:
<currencies>
<currency>CHF Swiss Francs</currency>
<currency>DEM German Deutsche Marks</currency>
<currency>GBP United Kingdom Pounds</currency>
<currency>JPY Japanese Yen</currency>
<currency>USD United States Dollars</currency>
</currencies>
JavaScript:
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("currencies.xml");
elem = xml_doc.documentElement.childNodes.item(1);
text = elem.firstChild
text.splitText(4);
len = elem.childNodes.length;
for (i = 0; i < len; i++)
document.write(elem.childNodes.item(i).data + "<br>");
DEM
German Deutsche Marks
The code in this example first loads the 'currencies.xml' file. Then it splits the text of the second 'currency' element into two at offset 4 (the fifth character in the string, which will become the first character of the new Text node). Finally the code iterates through the child nodes of the 'currency' element (now numbering 2) and displays the data property of each.