|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnu.xom.Node
nu.xom.ParentNode
nu.xom.Document
The Document
class represents
a complete XML document including its root element,
prolog, and epilog.
Constructor Summary | |
Document(Document doc)
Creates a copy of the Document . |
|
Document(Element root)
Creates a new Document object with the
specified root element. |
Method Summary | |
protected void |
checkRoot(Element root)
Subclasses can override this method to perform additional checks on the root element beyond what XML 1.0 requires. |
Node |
copy()
Returns a complete copy of this document. |
java.lang.String |
getBaseURI()
Returns the URI from which this document was loaded. |
DocType |
getDocType()
Returns this document's document type declaration, or null if it doesn't have one. |
Element |
getRootElement()
Returns this document's root element. |
java.lang.String |
getValue()
Returns the value of the document as defined by XPath 1.0. |
void |
insertChild(Node child,
int position)
Inserts a child node at the specified position. |
Node |
removeChild(int position)
Removes the child of this document at the specified position. |
Node |
removeChild(Node child)
Removes the specified child from this node. |
void |
setBaseURI(java.lang.String URI)
Sets the URI from which this node was loaded, and against which relative URLs in this node will be resolved. |
void |
setDocType(DocType doctype)
Sets this document's document type declaration. |
void |
setRootElement(Element root)
Replaces the current root element with a different root element. |
java.lang.String |
toString()
Returns a string representation of this node suitable for debugging and diagnosis. |
java.lang.String |
toXML()
Returns the actual complete, well-formed XML document as a String . |
Methods inherited from class nu.xom.ParentNode |
appendChild, checkInsertChild, checkRemoveChild, getChild, getChildCount, hasChildren, indexOf, replaceChild |
Methods inherited from class nu.xom.Node |
checkDetach, detach, equals, getDocument, getParent, hashCode |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Document(Element root)
Creates a new Document
object with the
specified root element.
root
- the root element of this documentpublic Document(Document doc)
Creates a copy of the Document
.
doc
- the Document to copyMethod Detail |
public final void insertChild(Node child, int position)
Inserts a child node at the specified position.
Inserting at position 0 makes the child the
first child of this node. Inserting at the position
getChildCount
makes the child the
last child of the node.
insertChild
in class ParentNode
position
- where to insert the childchild
- the node to insert
IllegalAddException
- if child
is not a
Comment
, ProcessingInstruction
,
or DocType
, or if child
is a
DocType
but this document already has a
DocType
MultipleParentException
- if child already has a parent
java.lang.NullPointerException
- if child is null
java.lang.IndexOutOfBoundsException
- if the position is negative
or greater than the number of children of the node.`public final DocType getDocType()
Returns this document's document type declaration, or null if it doesn't have one.
setDocType(nu.xom.DocType)
public final void setDocType(DocType doctype)
Sets this document's document type declaration. If this document already has a document type declaration, then it's inserted at that position. Otherwise, it's inserted at the beginning of the document.
doctype
- the document type declaration
MultipleParentException
- if doctype belongs to
another document
java.lang.NullPointerException
- if doctype is nullpublic final Element getRootElement()
Returns this document's root element. This is guaranteed to be non-null.
public final void setRootElement(Element root)
Replaces the current root element with a different root element.
root
- the new root element
MultipleParentException
- if root has a parent
XMLException
- if root is not legal for this
subclass of Document
java.lang.NullPointerException
- if root is nullprotected void checkRoot(Element root)
Subclasses can override this method to perform additional
checks on the root element beyond what XML 1.0 requires.
For example, an XHTMLDocument
subclass might
throw an exception if the proposed root element were not
an html
element.
root
- The new root element.
XMLException
- if the proposed root element
does not satisfy the local constraintspublic final Node removeChild(int position)
Removes the child of this document at the specified position.
Indexes begin at 0 and count up to one less than the number
of children of this document. The root element cannot be
removed. Instead, use setRootElement
to replace
the existing root element with a different element.
removeChild
in class ParentNode
position
- index of the node to remove
java.lang.IndexOutOfBoundsException
- if the index is negative or
greater than the number of children of this document - 1.
WellformednessException
- if the index points
to the root element.public final Node removeChild(Node child)
Removes the specified child from this node.
It throws a NoSuchChildException
if the node is not a child of this node.
The root element cannot be removed.
Instead, use setRootElement
to replace the
existing root element with a different element.
removeChild
in class ParentNode
child
- node to remove
NoSuchChildException
- if the node is not a
child of this node.
WellformednessException
- if child is the root element.public final void setBaseURI(java.lang.String URI)
Sets the URI from which this node was loaded, and against which relative URLs in this node will be resolved.
setBaseURI
in class ParentNode
URI
- the base URI of this document
MalformedURIException
- if URI
is
not a legal IRIpublic final java.lang.String getBaseURI()
Returns the URI from which this document was loaded.
getBaseURI
in class Node
public final java.lang.String getValue()
Returns the value of the document as defined by XPath 1.0. This is the same as the value of the root element, which is the complete PCDATA content of the root element, without any tags, comments, or processing instructions after all entity and character references have been resolved.
getValue
in class Node
Node.getValue()
public final java.lang.String toXML()
Returns the actual complete, well-formed XML document as a
String
. Significant white space is preserved.
Insignificant white space in tags, the prolog, the epilog,
and the internal DTD subset is not preserved.
Entity and character references are not preserved.
The entire document is contained in this one string.
toXML
in class Node
String
containing this entire
XML documentNode.toXML()
public Node copy()
Returns a complete copy of this document.
copy
in class Node
Document
objectNode.copy()
public final java.lang.String toString()
Returns a string representation of this node suitable for debugging and diagnosis. This is not the XML representation of this document.
toString
in class Node
Document
objectNode.toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |