Document interface represents the entire HTML or XML
document. Conceptually, it is the root of the document tree, and provides
the primary access to the document's data.
Since elements, text nodes, comments, processing instructions, etc.
cannot exist outside the context of a Document, the
Document interface also contains the factory methods needed
to create these objects. The Node objects created have a
ownerDocument attribute which associates them with the
Document within whose context they were created.
See also the Document Object Model (DOM) Level 3 Core Specification.
| Modifier and Type | Method and Description | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public Node | |||||||||||||||
| public Attr | Returns: A newAttr object with the nodeName
attribute set to name, and localName,
prefix, and namespaceURI set to
null. The value of the attribute is the empty string.The name of the attribute. name)Creates an | ||||||||||||||
| public Attr | Returns: A newAttr object with the following attributes:
The namespace URI of the attribute to create. namespaceURI, String The qualified name of the attribute to
instantiate. qualifiedName)Creates an attribute of the given qualified name and namespace URI. | ||||||||||||||
| public CDATASection | Returns: The newCDATASection object.The data for the data)CDATASection contents.Creates a | ||||||||||||||
| public Comment | Returns: The newComment object.The data for the node. data)Creates a | ||||||||||||||
| public DocumentFragment | |||||||||||||||
| public Element | Returns: A newElement object with the
nodeName attribute set to tagName, and
localName, prefix, and
namespaceURI set to null.The name of the element type to instantiate. For XML,
this is case-sensitive, otherwise it depends on the
case-sensitivity of the markup language in use. In that case, the
name is mapped to the canonical form of that markup by the DOM
implementation. tagName)Creates an element of the type specified. | ||||||||||||||
| public Element | Returns: A newElement object with the following
attributes:
The namespace URI of the element to create. namespaceURI, String The qualified name of the element type to
instantiate. qualifiedName)Creates an element of the given qualified name and namespace URI. | ||||||||||||||
| public EntityReference | Returns: The newEntityReference object.The name of the entity to reference.Unlike
name)Document.createElementNS or
Document.createAttributeNS, no namespace well-formed
checking is done on the entity name. Applications should invoke
Document.normalizeDocument() with the parameter "
namespaces" set to true in order to ensure that the
entity name is namespace well-formed.Creates an | ||||||||||||||
| public ProcessingInstruction | Returns: The newProcessingInstruction object.The target part of the processing instruction.Unlike
target, String Document.createElementNS or
Document.createAttributeNS, no namespace well-formed
checking is done on the target name. Applications should invoke
Document.normalizeDocument() with the parameter "
namespaces" set to true in order to ensure that the
target name is namespace well-formed.The data for the node. data)Creates a | ||||||||||||||
| public Text | Returns: The newText object.The data for the node. data)Creates a | ||||||||||||||
| public DocumentType | |||||||||||||||
| public Element | getDocumentElement()
This is a convenience attribute that allows direct access to the child node that is the document element of the document. | ||||||||||||||
| public String | getDocumentURI()
The location of the document or | ||||||||||||||
| public DOMConfiguration | |||||||||||||||
| public Element | Returns: The matching element ornull if there is none.The unique elementId)id value for an element.Returns the | ||||||||||||||
| public NodeList | Returns: A newNodeList object containing all the matched
Elements.The name of the tag to match on. The special value "*"
matches all tags. For XML, the tagname)tagname parameter is
case-sensitive, otherwise it depends on the case-sensitivity of the
markup language in use.Returns a | ||||||||||||||
| public NodeList | Returns: A newNodeList object containing all the matched
Elements.The namespace URI of the elements to match on. The
special value namespaceURI, String "*" matches all namespaces.The local name of the elements to match on. The
special value "*" matches all local names. localName)Returns a | ||||||||||||||
| public DOMImplementation | |||||||||||||||
| public String | getInputEncoding()
An attribute specifying the encoding used for this document at the time of the parsing. | ||||||||||||||
| public boolean | |||||||||||||||
| public String | getXmlEncoding()
An attribute specifying, as part of the XML declaration, the encoding of this document. | ||||||||||||||
| public boolean | getXmlStandalone()
An attribute specifying, as part of the XML declaration, whether this document is standalone. | ||||||||||||||
| public String | getXmlVersion()
An attribute specifying, as part of the XML declaration, the version number of this document. | ||||||||||||||
| public Node | Returns: The imported node that belongs to thisDocument.The node to import. importedNode, boolean If deep)true, recursively import the subtree under
the specified node; if false, import only the node
itself, as explained above. This has no effect on nodes that cannot
have any children, and on Attr, and
EntityReference nodes.Imports a node from another document to this document, without altering or removing the source node from the original document; this method creates a new copy of the source node. | ||||||||||||||
| public void | normalizeDocument()
This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form. | ||||||||||||||
| public Node | Returns: The renamed node. This is either the specified node or the new node that was created to replace the specified node.The node to rename. n, String The new namespace URI. namespaceURI, String The new qualified name. qualifiedName)Rename an existing node of type | ||||||||||||||
| public void | setDocumentURI(String documentURI)
The location of the document or | ||||||||||||||
| public void | setStrictErrorChecking(boolean strictErrorChecking)
An attribute specifying whether error checking is enforced or not. | ||||||||||||||
| public void | setXmlStandalone(boolean xmlStandalone)
An attribute specifying, as part of the XML declaration, whether this document is standalone. | ||||||||||||||
| public void | setXmlVersion(String xmlVersion)
An attribute specifying, as part of the XML declaration, the version number of this document. |
| adoptNode | back to summary |
|---|---|
| public Node adoptNode(Node source) throws DOMException Attempts to adopt a node from another document to this document. If
supported, it changes the
Note Since it does not create new nodes unlike the
| |
| createAttribute | back to summary |
|---|---|
| public Attr createAttribute(String name) throws DOMException Creates an
| |
| createAttributeNS | back to summary | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException Creates an attribute of the given qualified name and namespace URI.
| |||||||||||||||
| createCDATASection | back to summary |
|---|---|
| public CDATASection createCDATASection(String data) throws DOMException Creates a
| |
| createComment | back to summary |
|---|---|
| public Comment createComment(String data) Creates a | |
| createDocumentFragment | back to summary |
|---|---|
| public DocumentFragment createDocumentFragment() Creates an empty
| |
| createElement | back to summary |
|---|---|
| public Element createElement(String tagName) throws DOMException Creates an element of the type specified. Note that the instance
returned implements the
| |
| createElementNS | back to summary | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException Creates an element of the given qualified name and namespace URI.
| |||||||||||||
| createEntityReference | back to summary |
|---|---|
| public EntityReference createEntityReference(String name) throws DOMException Creates an Note If any descendant of the
| |
| createProcessingInstruction | back to summary |
|---|---|
| public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException Creates a
| |
| createTextNode | back to summary |
|---|---|
| public Text createTextNode(String data) Creates a | |
| getDoctype | back to summary |
|---|---|
| public DocumentType getDoctype() The Document Type Declaration (see
| |
| getDocumentElement | back to summary |
|---|---|
| public Element getDocumentElement() This is a convenience attribute that allows direct access to the child node that is the document element of the document. | |
| getDocumentURI | back to summary |
|---|---|
| public String getDocumentURI() The location of the document or
| |
| getDomConfig | back to summary |
|---|---|
| public DOMConfiguration getDomConfig() The configuration used when
| |
| getElementById | back to summary |
|---|---|
| public Element getElementById(String elementId) Returns the Note Attributes with the name "ID" or "id" are not of type ID unless so defined. | |
| getElementsByTagName | back to summary |
|---|---|
| public NodeList getElementsByTagName(String tagname) Returns a | |
| getElementsByTagNameNS | back to summary |
|---|---|
| public NodeList getElementsByTagNameNS(String namespaceURI, String localName) Returns a
| |
| getImplementation | back to summary |
|---|---|
| public DOMImplementation getImplementation() The | |
| getInputEncoding | back to summary |
|---|---|
| public String getInputEncoding() An attribute specifying the encoding used for this document at the time
of the parsing. This is
| |
| getStrictErrorChecking | back to summary |
|---|---|
| public boolean getStrictErrorChecking() An attribute specifying whether error checking is enforced or not. When
set to
| |
| getXmlEncoding | back to summary |
|---|---|
| public String getXmlEncoding() An attribute specifying, as part of the XML declaration, the encoding of this document. This is
| |
| getXmlStandalone | back to summary |
|---|---|
| public boolean getXmlStandalone() An attribute specifying, as part of the XML declaration, whether this document is standalone. This is Note No verification is done on the value when setting
this attribute. Applications should use
| |
| getXmlVersion | back to summary |
|---|---|
| public String getXmlVersion() An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if
this document supports the "XML" feature, the value is
| |
| importNode | back to summary |
|---|---|
| public Node importNode(Node importedNode, boolean deep) throws DOMException Imports a node from another document to this document, without altering
or removing the source node from the original document; this method
creates a new copy of the source node. The returned node has no
parent; (
| |
| normalizeDocument | back to summary |
|---|---|
| public void normalizeDocument() This method acts as if the document was going through a save and load
cycle, putting the document in a "normal" form. As a consequence,
this method updates the replacement tree of
// Keep in the document
the information defined // in the XML Information Set (Java example)
DOMConfiguration docConfig = myDocument.getDomConfig();
docConfig.setParameter("infoset", Boolean.TRUE);
myDocument.normalizeDocument();
Mutation events, when supported, are generated to reflect the changes occurring on the document. If errors occur during the invocation of this method, such as an attempt to update a read-only node or a Node.nodeName
contains an invalid character according to the XML version in use,
errors or warnings (DOMError.SEVERITY_ERROR or
DOMError.SEVERITY_WARNING) will be reported using the
DOMErrorHandler object associated with the "error-handler
" parameter. Note this method might also report fatal errors (
DOMError.SEVERITY_FATAL_ERROR) if an implementation
cannot recover from an error.
| |
| renameNode | back to summary |
|---|---|
| public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException Rename an existing node of type
| |
| setDocumentURI | back to summary |
|---|---|
| public void setDocumentURI(String documentURI) The location of the document or
| |
| setStrictErrorChecking | back to summary |
|---|---|
| public void setStrictErrorChecking(boolean strictErrorChecking) An attribute specifying whether error checking is enforced or not. When
set to
| |
| setXmlStandalone | back to summary |
|---|---|
| public void setXmlStandalone(boolean xmlStandalone) throws DOMException An attribute specifying, as part of the XML declaration, whether this document is standalone. This is Note No verification is done on the value when setting
this attribute. Applications should use
| |
| setXmlVersion | back to summary |
|---|---|
| public void setXmlVersion(String xmlVersion) throws DOMException An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if
this document supports the "XML" feature, the value is
| |