Class Text
- java.lang.Object
-
- nu.xom.Node
-
- nu.xom.Text
-
public class Text extends Node
This class represents a run of text. CDATA sections are not treated differently than normal text.
Textobjects may be adjacent to otherTextobjects.The maximum size of a String or an array in Java limits the maximum size of a text node to about 2 gigabytes. If you're stuffing Base-64 encoded movies inside one node, you will have problems. Try breaking up the text into smaller, contiguous chunks. Even then you will probably not be able to use XPath on the result.
- Version:
- 1.3.0
- Author:
- Elliotte Rusty Harold
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Textcopy()Returns a deep copy of thisTextwith no parent, that can be added to this document or a different one.NodegetChild(int position)ThrowsIndexOutOfBoundsExceptionbecause texts do not have children.intgetChildCount()Returns 0 because texts do not have children.java.lang.StringgetValue()Returns the XPath 1.0 string-value of thisTextnode.voidsetValue(java.lang.String data)Sets the content of theTextobject to the specified data.java.lang.StringtoString()Returns aStringrepresentation of thisTextsuitable for debugging and diagnosis.java.lang.StringtoXML()Returns a string containing the XML serialization of this text node.-
Methods inherited from class nu.xom.Node
detach, equals, getBaseURI, getDocument, getParent, hashCode, query, query
-
-
-
-
Constructor Detail
-
Text
public Text(java.lang.String data)
This constructor creates a new
Textobject. 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
Textobject.- Parameters:
text- theTextobject to copy
-
-
Method Detail
-
setValue
public void setValue(java.lang.String data)
Sets the content of the
Textobject 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. Passing null is the same as passing the empty string.- 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
-
getValue
public final java.lang.String getValue()
Returns the XPath 1.0 string-value of this
Textnode. The XPath string-value of a text node is the same as the text of the node.
-
getChild
public final Node getChild(int position)
Throws
IndexOutOfBoundsExceptionbecause texts do not have children.
-
getChildCount
public final int getChildCount()
Returns 0 because texts do not have children.
- Specified by:
getChildCountin classNode- Returns:
- zero
-
copy
public Text copy()
Returns a deep copy of this
Textwith no parent, that can be added to this document or a different one.
-
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&and<. It escapes the carriage return (\r) as
. If this text node is a CDATA section, then it may wrap the value in CDATA section delimiters instead of escaping.
-
toString
public final java.lang.String toString()
Returns a
Stringrepresentation of thisTextsuitable for debugging and diagnosis. This is not the XML representation of thisTextnode.- Overrides:
toStringin classjava.lang.Object- Returns:
- a non-XML string representation of this node
-
-