DOM Document
XML DOM - Document Object
The Document object represents the entire XML document.
Document Object
The Document object is the root of the document tree and provides us with the initial (or top-level) access to the document data.
Since element nodes, text nodes, comments, processing instructions, etc. cannot exist outside the document, the Document object also provides methods for creating these objects. Node objects provide an ownerDocument property that associates them with the Document in which they were created.
Document object properties
Properties | Description |
---|---|
async | Specify whether the download of XML files should be handled asynchronously. |
childNodes | Returns the node list of the document's child nodes. |
doctype | Returns the document type declaration (DTD, full name Document Type Declaration) related to the document. |
documentElement | Returns the root node of the document. |
documentURI | Sets or returns the location of the document. |
domConfig | Returns the configuration used when normalizeDocument() is called. |
firstChild | Returns the first child node of the document. |
implementation | Returns the DOMImplementation object that handles this document. |
inputEncoding | Returns the encoding used for the document (when parsing). |
lastChild | Returns the last child node of the document. |
nodeName | Returns the name of the node (according to the node's type). |
nodeType | Returns the node type of the node. |
nodeValue | Sets or returns the value of a node (according to the node's type). |
strictErrorChecking | Set or return whether to force error checking. |
xmlEncoding | Returns the XML encoding of the document. |
xmlStandalone | Set or return whether the document is standalone. |
xmlVersion | Set or return the XML version of the document. |
Document Object Method
Method | Description |
---|---|
adoptNode(sourcenode) | Select a node from another document to this document, and then return the selected node. |
createAttribute(name) | Creates an attribute node with the specified name and returns a new Attr object. |
createAttributeNS(uri,name) | Creates an attribute node with the specified name and namespace, and returns a new Attr object. |
createCDATASection() | Create a CDATA section node. |
createComment() | Create a comment node. |
createDocumentFragment() | Create an empty DocumentFragment object and return this object. |
createElement() | Create element node. |
createElementNS() | Create an element node with the specified namespace. |
createEntityReference(name) | Create an EntityReference object and return this object. |
createProcessingInstruction(target,data) | Create a ProcessingInstruction object and return this object. |
createTextNode() | Create a text node. |
getElementById(id) | Returns the element with the ID attribute of the specified value. If no such element exists, null is returned. |
getElementsByTagName() | Returns a NodeList of all elements with the specified name. |
getElementsByTagNameNS() | Returns a NodeList of all elements with the specified name and namespace. |
importNode(nodetoimport,deep) | Select a node from another document to this document. This method creates a new copy of the source node. If the deep parameter is set to true, it will import all child nodes of the specified node. If set to false, it will only import the node itself. This method returns the imported node. |
normalizeDocument() | |
Rename an element or attribute node. |