This interface represents a DOM document, and
an object that implements this interface serves as the root of a DOM
document tree. Most of the methods defined by the Document interface
are "factory methods" that are used
to create various types of nodes that can be inserted into this
document. Note that there are two versions of the methods for
creating attributes and elements. The methods with
"NS" in their name are
namespace-aware and require the attribute or element name to be
specified as a combination of a namespace URI and a local name.
You'll notice that throughout the
DOM API, methods with
"NS" in their names are
namespace-aware. Other important methods include the following:
getElementsByTagName( ) and its namespace-aware
variant getElementsByTagNameNS( ) search the
document tree for Element nodes that have the
specified tag name and return a NodeList
containing those matching nodes. The Element
interface defines methods by the same names that search only within
the subtree defined by an Element.
getElementById( ) is a related method that
searches the document tree for a single element with the specified
unique value for an ID attribute. This is useful
when you use an ID attribute to uniquely identify
certain tags within an XML document. Note that this method does not
search for attributes that are named
"id" or
"ID". It searches for attributes
whose XML type (as declared in the document's DTD)
is ID. Such attributes are often named
"id", but this is not required.
An XML document must have a single root element.
getdocumentElement( ) returns this
Element object. Note, however that this does not
mean that a Document node has only one child. It
must have exactly one child that is an Element,
but it can also have other children such as
Comment and
ProcessingInstruction nodes. The
geTDoctype( ) method returns the
DocumentType object (or null if
there isn't one) that represents the
document's DTD. getImplementation(
) returns the the DOMImplementation
object that represents the DOM implementation that created this
document tree.
Figure 21-5. org.w3c.dom.Document
public interface
Document extends Node {
// Public Instance Methods
5.0 Node
adoptNode (Node
source ) throws DOMException;
Attr
createAttribute (String
name ) throws DOMException;
Attr
createAttributeNS (String
namespaceURI , String
qualifiedName )
throws DOMException;
CDATASection
createCDATASection (String
data ) throws DOMException;
Comment
createComment (String
data );
DocumentFragment
createDocumentFragment ( );
Element
createElement (String
tagName ) throws DOMException;
Element
createElementNS (String
namespaceURI , String
qualifiedName )
throws DOMException;
EntityReference
createEntityReference (String
name ) throws DOMException;
ProcessingInstruction
createProcessingInstruction (String
target ,
String
data ) throws DOMException;
Text
createTextNode (String
data );
DocumentType
getDoctype ( );
Element
getDocumentElement ( );
5.0 String
getDocumentURI ( );
5.0 DOMConfiguration
getDomConfig ( );
Element
getElementById (String
elementId );
NodeList
getElementsByTagName (String
tagname );
NodeList
getElementsByTagNameNS (String
namespaceURI , String
localName );
DOMImplementation
getImplementation ( );
5.0 String
getInputEncoding ( );
5.0 boolean
getStrictErrorChecking ( );
5.0 String
getXmlEncoding ( );
5.0 boolean
getXmlStandalone ( );
5.0 String
getXmlVersion ( );
Node
importNode (Node
importedNode , boolean
deep ) throws DOMException;
5.0 void
normalizeDocument ( );
5.0 Node
renameNode (Node
n , String
namespaceURI , String
qualifiedName )
throws DOMException;
5.0 void
setDocumentURI (String
documentURI );
5.0 void
setStrictErrorChecking (boolean
strictErrorChecking );
5.0 void
setXmlStandalone (boolean
xmlStandalone ) throws DOMException;
5.0 void
setXmlVersion (String
xmlVersion ) throws DOMException;
}
javax.xml.parsers.DocumentBuilder.{newDocument( ),
parse( )},
DOMImplementation.createDocument( ),
Node.getOwnerDocument( )