XML DOM Document Object

The Document object represents the entire XML document.

XML document object

The Document object is the root of an XML document tree, providing us with the main entry points to access document data.

Since element nodes, text nodes, comments, processing instructions, and others cannot exist outside of the document, the Document object also includes methods for creating these objects. The Node object has an ownerDocument property that associates it with the Document that created it.

Properties of the Document object

Attribute Description
childNodes Return the NodeList of child nodes of the document.
doctype Return the document type declaration associated with the document.
documentElement Return the root node of the document.
documentURI Set or return the position of the document.
domConfig Return the configuration used when calling normalizeDocument().
firstChild Return the first child node of the document.
implementation Return the DOMImplementation object that handles this document.
inputEncoding Return the encoding method used by the document (at parsing time).
lastChild Return the last child of the document.
nodeName Return the name of the node (depending on its type).
nodeType Return the node type of the node.
nodeValue Set or return the value of the node (depending on its type).
xmlEncoding Return 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.

Methods of Document object

Method Description
adoptNode() Adopt a node from another document into this document, and return the adopted node.
createAttribute() Create an attribute node with the specified name, and return a new Attr object.
createAttributeNS() Create an attribute node with the specified name and namespace, and return a new Attr object.
createCDATASection() Create a CDATA section node.
createComment() Create a comment node.
createDocumentFragment() Create an empty DocumentFragment object and return it.
createElement() Create an element node.
createElementNS() Create an element node with the specified namespace.
createEntityReference() Create an EntityReference object and return this object.
createProcessingInstruction() Create a ProcessingInstruction object and return this object.
createTextNode() Create a text node.
getElementById() Return the element with the id attribute having the given value.
getElementsByTagName() Return a NodeList of all elements with the specified name.
getElementsByTagNameNS() Return a NodeList of all elements with the specified name and namespace.
importNode() Import a node from another document to this document.
normalizeDocument()
renameNode() Rename element nodes or attribute nodes.

Properties of DocumentType object

Each document has a DOCTYPE attribute, which is either null or a DocumentType object.

The DocumentType object provides an interface for entities defined for XML documents.

Attribute Description
name Return the name of the DTD.
publicId Return the public identifier of the DTD.
systemId Return the system identifier of the external DTD.

Methods of the DocumentImplementation object

The DOMImplementation object performs operations that are independent of any specific instance of the Document Object Model.

Method Description
createDocument() Create a new DOM Document object of the specified document type.
createDocumentType() Create an empty DocumentType node.
getFeature() Returns an object (if any) that implements the API for the specified features and versions.
hasFeature() Check if the DOM implementation has implemented a specific feature and version.

Properties of the ProcessingInstruction object

The ProcessingInstruction object represents a processing instruction.

Processing instructions are used as a method to retain processor-specific information within the XML document text.

Attribute Description
data Set or return the content of the processing instruction.
target Return the target of the processing instruction.