XML DOM tutoria...login
XML DOM tutorial
author:php.cn  update time:2022-04-13 15:27:56

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

PropertiesDescription
asyncSpecify whether the download of XML files should be handled asynchronously.
childNodesReturns the node list of the document's child nodes.
doctypeReturns the document type declaration (DTD, full name Document Type Declaration) related to the document.
documentElementReturns the root node of the document.
documentURISets or returns the location of the document.
domConfigReturns the configuration used when normalizeDocument() is called.
firstChildReturns the first child node of the document.
implementationReturns the DOMImplementation object that handles this document.
inputEncodingReturns the encoding used for the document (when parsing).
lastChildReturns the last child node of the document.
nodeNameReturns the name of the node (according to the node's type).
nodeTypeReturns the node type of the node.
nodeValueSets or returns the value of a node (according to the node's type).
strictErrorCheckingSet or return whether to force error checking.
xmlEncodingReturns the XML encoding of the document.
xmlStandaloneSet or return whether the document is standalone.
xmlVersionSet or return the XML version of the document.

Document Object Method

##renameNode()Rename an element or attribute node.
MethodDescription
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()