nu.xom
Class Document
The Document
class represents
a complete XML document including its root element,
prolog, and epilog.
Node | copy() -
Returns a complete copy of this document.
|
String | getBaseURI() -
Returns the absolute 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.
|
String | getValue() -
Returns the value of the document as defined by XPath 1.0.
|
Node | removeChild(int position) -
Removes the child of this document at the specified position.
|
Node | removeChild(Node child) -
Removes the specified child from this document.
|
void | replaceChild(Node oldChild, Node newChild) -
Replaces an existing child with a new child node.
|
void | setBaseURI(String URI) -
Sets the URI from which this document was loaded, and
against which relative URLs in this document 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.
|
String | toString() -
Returns a string representation of this document suitable
for debugging and diagnosis.
|
String | toXML() -
Returns the actual complete, well-formed XML document as a
String .
|
copy , detach , equals , getBaseURI , getChild , getChildCount , getDocument , getParent , getValue , hashCode , query , query , toXML |
Document
public Document(Document doc)
Creates a copy of this document.
doc
- the document to copy
Document
public Document(Element root)
Creates a new Document
object with the
specified root element.
root
- the root element of this document
copy
public Node copy()
Returns a complete copy of this document.
- copy in interface Node
- a deep copy of this
Document
object
getBaseURI
public final String getBaseURI()
Returns the absolute URI from which this document was loaded.
This method returns the empty string if the base URI is not
known; for instance if the document was created in memory with
a constructor rather than by parsing an existing document.
- getBaseURI in interface Node
- the base URI of this document
getDocType
public final DocType getDocType()
Returns this document's document type declaration,
or null if it doesn't have one.
- the document type declaration
getRootElement
public final Element getRootElement()
Returns this document's root element.
This is guaranteed to be non-null.
getValue
public final 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 interface Node
- value of the root element of this document
removeChild
public 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 interface ParentNode
position
- index of the node to remove
- the node which was removed
removeChild
public Node removeChild(Node child)
Removes the specified child from this document.
The root element cannot be removed.
Instead, use setRootElement
to replace the
existing root element with a different element.
- removeChild in interface ParentNode
- the node which was removed
replaceChild
public void replaceChild(Node oldChild,
Node newChild)
Replaces an existing child with a new child node.
If oldChild
is not a child of this node,
then a NoSuchChildException
is thrown.
The root element can only be replaced by another element.
- replaceChild in interface ParentNode
oldChild
- the node removed from the treenewChild
- the node inserted into the tree
setBaseURI
public void setBaseURI(String URI)
Sets the URI from which this document was loaded, and
against which relative URLs in this document will be resolved.
Setting the base URI to null or the empty string removes any
existing base URI.
- setBaseURI in interface ParentNode
URI
- the base URI of this document
setDocType
public 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
setRootElement
public void setRootElement(Element root)
Replaces the current root element with a different root element.
root
- the new root element
toString
public final String toString()
Returns a string representation of this document suitable
for debugging and diagnosis. This is not
the XML representation of this document.
- a non-XML string representation of this document
toXML
public final 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 interface Node
- a string containing this entire XML document
Copyright 2002-2005 Elliotte Rusty Harold
elharo@metalab.unc.edu