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( 15 );
}
catch (DOMException err) { ... }

This is useful for inserting other nodes into the text, such as a comment or entity reference node.

Create text node

A new Text node can be created using the createTextNode factory method defined in the Document interface.

The following example creates a Text node, then appends it to the content of an element:

Text newTextNode = myDoc.createTextNode( "the text" );

anElement.appendNode( newTextNode );

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.114.142