XML DOM - DocumentObject


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 entry point to the document data.

Since element nodes, text nodes, comments, processing instructions, etc. cannot exist outside a document, the Document object also provides methods for creating 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 download of an XML file should be processed asynchronously.
childNodes Returns a node list of the child nodes of the document.
doctype Returns the document type declaration (DTD, full name 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 processes 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 a node (depending on its type).
nodeType Returns the node type of the node.
nodeValue Sets or returns the value of a node (depending on 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

Methods Description
adoptNode(sourcenode) Selects a node from another document into this document, and returns the selected 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() Create a comment node.
createDocumentFragment() Creates an empty DocumentFragment object, and returns this object.
createElement() Create 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() Create a text node.
getElementById(id) Returns the element with an ID attribute with 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) Selects 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. This method returns the imported node.
normalizeDocument()
renameNode() Renames an element or attribute node.

other extensions