XML technologies / XML / XML in a Nutshell / DOM reference / Object reference / Text
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
Text nodes contain the actual text data of an XML document, clearly distinct from markup. After the parser reads the document, each contiguous text region has exactly one Text node.
Attributes
The interface Text defines the following attributes:
wholeText: DOMString (3)
This convenience attribute returns, in document order, all the text of the target node and adjacent Text nodes. For this attribute, Text nodes are considered adjacent if reachable without entering, leaving, or skipping any of the following node types: Element, Comment and ProcessingInstruction. Read-only.
Java binding
public String getWholeText( );
isElementContentWhitespace: boolean (3)
Returns true, if the element contains only whitespace determined to be insignificant during XML validation. Whitespace is insignificant if it does not belong to an element declared to contain text or mixed content. Read-only.
Java binding
public boolean isElementContentWhitespace( );
Methods
For the interface Text the following methods are defined:
replaceWholeText: content (3)
This convenience method replaces several adjacent text nodes with one text node containing the text supplied by the argument content. It returns a reference to the Text node receiving the new content, or null, if content contained a zero-length string.
Argument
Exceptions
NO_MODIFICATION_ALLOWED_ERR
Raised if the element is read-only.
splitText: offset
The Text node is split into two consecutive Text nodes. The original node’s content is divided into two substrings. The second becomes the new node’s value; the first remains in the original node. If the node is currently part of the DOM tree, the new node containing the split-off text becomes the original node’s next sibling. The method returns the new Text node containing the second part of the text data.
Argument
offset (unsigned long)
Position at which to split the content, starting at 0.
Exceptions
INDEX_SIZE_ERR
The supplied offset was invalid; it must satisfy 0 <=
offset<=length.NO_MODIFICATION_ALLOWED_ERR
Raised if the element is read-only.
Java binding
public Text splitText(long offset) throws DOMException;
Java example
// Erzeuge einen Textknoten
long = doc.createTextNode("Dieser Text wird geteilt.");
// und teile ihn in zwei Knoten auf.
Text ndSplit = ndText.splitText(9);Note: The interface Text derives from the interface CharacterData. Also see the notes on the interface CharacterData. They provide a complete overview of methods for accessing character data in nodes of this type.
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de