Name

Text

Synopsis

A Text node represents a run of plain text that does not contain any XML markup. Plain text appears within XML elements and attributes, and Text nodes typically appear as children of Element and Attr nodes. Text nodes inherit from CharacterData, and the textual content of a Text node is available through the getData( ) method inherited from CharacterData or through the getNodeValue( ) method inherited from Node.

Text nodes may be manipulated using any of the methods inherited from CharacterData. The Text interface defines one method of its own: splitText( ) splits a Text node at the specified character position. The method changes the original node so that it contains only the text up to the specified position. Then it creates a new Text node that contains the text from the specified position on and inserts that new node into the document tree immediately after the original one. The Node.normalize( ) method reverses this process by deleting emty Text nodes and merging adjacent Text nodes into a single node.

Text nodes never have children.

org.w3c.dom.Text

Figure 21-14. org.w3c.dom.Text

public interface Text extends CharacterData {
// Public Instance Methods
                  5.0  String getWholeText( );  
5.0  boolean isElementContentWhitespace( );  
5.0  Text replaceWholeText(String content) throws DOMException;  
     Text splitText(int offset) throws DOMException;  
}

Implementations

CDATASection

Returned By

Document.createTextNode( ...

Get Java in a Nutshell, 5th 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.