nu.xom
Class Comment
This class represents an XML comment such as
<-- This is a comment-->
.
A comment node cannot have any child nodes.
It can be a child of an Element
or a Document
.
It has essentially no internal substructure.
Comment(String data) -
Creates a new
Comment object from string data.
|
Comment(Comment comment) -
Creates a new comment that's a copy of its argument.
|
Node | copy() -
Returns a deep copy of this
Comment object
which contains the same text, but does not have any parent.
|
Node | getChild(int position) -
Throws
IndexOutOfBoundsException because
comments do not have children.
|
int | getChildCount() -
Returns 0 because comments do not have children.
|
String | getValue() -
Returns the value of this comment as defined by XPath 1.0.
|
void | setValue(String data) -
Sets the content of this
Comment object
to the specified string.
|
String | toString() -
Returns a string form of the comment suitable for debugging
and diagnosis.
|
String | toXML() -
Returns a
String containing the actual XML
form of the comment;
for example, <--This is a comment--> .
|
copy , detach , equals , getBaseURI , getChild , getChildCount , getDocument , getParent , getValue , hashCode , query , query , toXML |
Comment
public Comment(String data)
Creates a new Comment
object from string data.
The data is checked for legality according to XML 1.0 rules.
Illegal characters such as the form feed and null are not
allowed. Furthermore, the two hyphen string "--" is not allowed;
and the last character of the comment may not be a hyphen.
data
- the initial text of the comment
Comment
public Comment(Comment comment)
Creates a new comment that's a copy of its argument.
The copy has the same data but no parent node.
comment
- the comment to copy
copy
public Node copy()
Returns a deep copy of this Comment
object
which contains the same text, but does not have any parent.
Thus, it can be inserted into a different document.
- copy in interface Node
- a deep copy of this
Comment
that is not part of a document
getChild
public final Node getChild(int position)
Throws IndexOutOfBoundsException
because
comments do not have children.
- getChild in interface Node
position
- the index of the child node to return
- never returns because comments do not have children;
Always throws an exception.
getChildCount
public final int getChildCount()
Returns 0 because comments do not have children.
- getChildCount in interface Node
getValue
public final String getValue()
Returns the value of this comment as defined by XPath 1.0.
The XPath string-value of a comment node is the string
content of the node, not including the initial
<--
and closing -->
.
- getValue in interface Node
- the content of the comment
setValue
public void setValue(String data)
Sets the content of this Comment
object
to the specified string.
This string is checked for legality according to XML 1.0 rules.
Characters that can be serialized such as < and &
are allowed. However, illegal characters such as the form feed
and unmatched halves of surrogate pairs are not allowed.
Furthermore, the string may not contain a double hyphen
(--
) and may not end with a hyphen.
data
- the text to install in the comment
toString
public final String toString()
Returns a string form of the comment suitable for debugging
and diagnosis. It deliberately does not return an actual
XML comment.
- a representation of the
Comment
as a String
toXML
public final String toXML()
Returns a String
containing the actual XML
form of the comment;
for example, <--This is a comment-->
.
- toXML in interface Node
- a
String
containing a well-formed
XML comment
Copyright 2002-2005 Elliotte Rusty Harold
elharo@metalab.unc.edu