Class Comment
- java.lang.Object
-
- nu.xom.Node
-
- nu.xom.Comment
-
public class Comment extends Node
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 anElementor aDocument. It has essentially no internal substructure.- Version:
- 1.3.0
- Author:
- Elliotte Rusty Harold
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Commentcopy()Returns a deep copy of thisCommentobject which contains the same text, but does not have any parent.NodegetChild(int position)ThrowsIndexOutOfBoundsExceptionbecause comments do not have children.intgetChildCount()Returns 0 because comments do not have children.java.lang.StringgetValue()Returns the value of this comment as defined by XPath 1.0.voidsetValue(java.lang.String data)Sets the content of thisCommentobject to the specified string.java.lang.StringtoString()Returns a string form of the comment suitable for debugging and diagnosis.java.lang.StringtoXML()Returns aStringcontaining the actual XML form of the comment; for example,<--This is a comment-->.-
Methods inherited from class nu.xom.Node
detach, equals, getBaseURI, getDocument, getParent, hashCode, query, query
-
-
-
-
Constructor Detail
-
Comment
public Comment(java.lang.String data)
Creates a new
Commentobject 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 must not be a hyphen.- Parameters:
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.
- Parameters:
comment- the comment to copy
-
-
Method Detail
-
getValue
public final java.lang.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-->.
-
setValue
public void setValue(java.lang.String data)
Sets the content of this
Commentobject 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.- Parameters:
data- the text to install in the comment
-
getChild
public final Node getChild(int position)
Throws
IndexOutOfBoundsExceptionbecause comments do not have children.
-
getChildCount
public final int getChildCount()
Returns 0 because comments do not have children.
- Specified by:
getChildCountin classNode- Returns:
- zero
-
copy
public Comment copy()
Returns a deep copy of this
Commentobject which contains the same text, but does not have any parent. Thus, it can be inserted into a different document.
-
toXML
public final java.lang.String toXML()
Returns a
Stringcontaining the actual XML form of the comment; for example,<--This is a comment-->.
-
toString
public final java.lang.String toString()
Returns a string form of the comment suitable for debugging and diagnosis. It deliberately does not return an actual XML comment.
- Overrides:
toStringin classjava.lang.Object- Returns:
- a representation of the
Commentas aString
-
-