nu.xom
Class Text

java.lang.Object
  extended bynu.xom.Node
      extended bynu.xom.LeafNode
          extended bynu.xom.Text

public class Text
extends LeafNode

This class represents a run of text. CDATA sections are not treated differently than normal text.

Version:
1.0d23
Author:
Elliotte Rusty Harold

Constructor Summary
Text(java.lang.String data)
           This constructor creates a new Text object.
Text(Text text)
           Creates a copy of the specified Text object.
 
Method Summary
protected  void checkValue(java.lang.String data)
           Subclasses can override this method to perform additional checks.
 Node copy()
           Returns a deep copy of this Text with no parent, that can be added to this document or a different one.
 java.lang.String getValue()
           Returns the XPath 1.0 string-value of this Text node.
 void setValue(java.lang.String data)
           This sets the content of the Text object to the specified data.
 java.lang.String toString()
           Returns a String representation of this Text suitable for debugging and diagnosis.
 java.lang.String toXML()
           Returns a string containing the XML serialization of this text node.
 
Methods inherited from class nu.xom.LeafNode
getChild, getChildCount, hasChildren
 
Methods inherited from class nu.xom.Node
checkDetach, detach, equals, getBaseURI, getDocument, getParent, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Text

public Text(java.lang.String data)

This constructor creates a new Text object. The data is checked for legality according to XML 1.0 rules. Characters that can be serialized by escaping them such as < and & are allowed. However, characters such as the form feed, null, vertical tab, unmatched halves of surrogate pairs, and 0xFFFE and 0xFFFF are not allowed.

Parameters:
data - the initial text of the object
Throws:
IllegalCharacterDataException - if data contains any characters which are illegal in well-formed XML 1.0 such as null, vertical tab, or unmatched halves of surrogate pairs

Text

public Text(Text text)

Creates a copy of the specified Text object.

Parameters:
text - the Text object to copy
Method Detail

setValue

public final void setValue(java.lang.String data)

This sets the content of the Text object to the specified data. The data is checked for legality according to XML 1.0 rules. Characters that can be serialized such as < and & are allowed. However, characters such as the form feed, null, vertical tab, unmatched halves of surrogate pairs, and 0xFFFE and 0xFFFF are not allowed.

Parameters:
data - the text to install in the object
Throws:
IllegalCharacterDataException - if data contains any characters which are illegal in well-formed XML 1.0 such as null, vertical tab, or unmatched halves of surrogate pairs

checkValue

protected void checkValue(java.lang.String data)

Subclasses can override this method to perform additional checks. For example, an Integer subclass could verify that the text was a legal base-10 integer. However, this can only be used to add checks, not remove them. All text in text nodes must be potentially well-formed when serialized.

Parameters:
data - the text to check

getValue

public final java.lang.String getValue()

Returns the XPath 1.0 string-value of this Text node. The XPath string-value of a text node is the same as the text of the node.

Specified by:
getValue in class Node
Returns:
The content of the node.
See Also:
Node.getValue()

copy

public Node copy()

Returns a deep copy of this Text with no parent, that can be added to this document or a different one.

Specified by:
copy in class Node
Returns:
a deep copy of this text node with no parent
See Also:
Node.copy()

toXML

public final java.lang.String toXML()

Returns a string containing the XML serialization of this text node. Unlike getValue, this method escapes characters such as & and < using entity references such as &amp; and &lt;. It escapes the carriage return (\r) as &#x0D;.

Specified by:
toXML in class Node
Returns:
the string form of this text node
See Also:
Node.toXML()

toString

public final java.lang.String toString()

Returns a String representation of this Text suitable for debugging and diagnosis. This is not the XML representation of this Text node.

Specified by:
toString in class Node
Returns:
a non-XML string representation of this node
See Also:
Object.toString()


Copyright 2002-2004 Elliotte Rusty Harold
elharo@metalab.unc.edu