Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM - Document Object

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's data.

Since element nodes, text nodes, comments, processing instructions, etc. cannot exist outside of a document, the Document object also provides methods for creating these objects. The Node object provides an ownerDocument property that associates them with the Document in which they were created.

Document Object Properties

property Description
async Specifies whether the downloading of the XML file should be processed asynchronously.
childNodes Returns a NodeList of the document's child nodes.
doctype Returns the document type declaration (DTD, short for Document Type Declaration) 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 first child node of the document.
implementation Returns the DOMImplementation object that handles the document.
inputEncoding Returns the encoding used for the document (at parsing time).
lastChild Returns the last child node of the document.
nodeName Returns the name of the node (according to its type).
nodeType Returns the node type of the node.
nodeValue Sets or returns the value of the node (according to its 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 into this document, then returns the adopted node.
createAttribute(name) Creates an attribute node with the specified name and returns the new Attr object.
createAttributeNS(uri,name) Creates an attribute node with the specified name and namespace, and returns the new Attr object.
createCDATASection() Creates a CDATA section node.
createComment() Creates a comment node.
createDocumentFragment() Creates an empty DocumentFragment object and returns it.
createElement() Create an element node.
createElementNS() Creates an element node with the specified namespace.
createEntityReference(name) Creates an EntityReference object and returns it.
createProcessingInstruction(target,data) Creates a ProcessingInstruction object and returns it.
createTextNode() Create a text node.
getElementById(id) Returns the element with an ID attribute of the specified value. If no such element exists, 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) Imports a node from another document into 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 imports only the node itself. The method returns the imported node.
normalizeDocument()
renameNode() Renames an element or attribute node.