Text

Next to Element nodes, Text nodes are likely to be the most common in the average DOM tree. They tend to be children of Element nodes, and are always leaf nodes. The Text interface extends the CharacterData interface, so that the content of a Text node can be modified using the methods described above, but also adds the following single method:

Text  splitText( int offset ) throws DOMException;

Split text into two nodes

The splitText method is used to split one Text node into two adjacent Text nodes, at the location in the string given in the parameter.

The first part is considered to be the original node. The second part is a new node, and a reference to this new node is returned by the method:

try
{
  Text myTextNode = aTextNode.splitText ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.