Easy Tutorial
❮ Prop Node Baseuri Met Cdata Deletedata ❯

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 to create these objects. The Node object provides an ownerDocument property, which associates them with the Document in which they were created.

Document Object Properties

Property Description
async Specifies whether the XML file download should be handled asynchronously.
childNodes Returns a node list of the document's child nodes.
doctype Returns the Document Type Declaration (DTD) associated with 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 document's first child node.
implementation Returns the DOMImplementation object that handles this document.
inputEncoding Returns the encoding used for the document (at the time of parsing).
lastChild Returns the document's last child node.
nodeName Returns the name of the node (depending on the node type).
nodeType Returns the node type of the node.
nodeValue Sets or returns the value of the node (depending on the node type).
strictErrorChecking Sets or returns whether error checking is enforced.
xmlEncoding Returns the XML encoding of the document.
xmlStandalone Sets or returns whether the document is standalone.
xmlVersion Sets or returns the XML version of the document.

Document Object Methods

Method Description
adoptNode(sourcenode) Adopts a node from another document to this document and returns the adopted 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() Creates a CDATA section node.
createComment() Creates a comment node.
createDocumentFragment() Creates an empty DocumentFragment object and returns this object.
createElement() Creates an element node.
createElementNS() Creates an element node with the specified namespace.
createEntityReference(name) Creates an EntityReference object and returns this object.
createProcessingInstruction(target,data) Creates a ProcessingInstruction object and returns this object.
createTextNode() Creates a text node.
getElementById(id) Returns the element with the specified ID attribute. If no such element exists, it returns null.
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) Adopts 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 imports all child nodes of the specified node. If set to false, it only imports the node itself. The method returns the imported node.
normalizeDocument()
renameNode() Renames an element or attribute node.
❮ Prop Node Baseuri Met Cdata Deletedata ❯