XML DOM » Objects » Document

The Document object represents the entire XML document and is the primary means of access to it; it represents the top node of the DOM tree. Since none of the other nodes can exist outside of a document, it also contains all the factory methods necessary to create them. Once created, these child Node objects will each have an ownerDocument attribute associating them with the parent document.

Microsoft's implementation includes all of the base DOM document methods as well as additional methods and properties that support XSL and XML transformations. The document is the only object that can be created, all other objects and interfaces being accessed or created from within it.

There are two models of the Document: the free-threaded model and the rental threading model. They both behave exactly the same but differ in that the rental-treaded versions offer better performance because the parser doesn't need to manage concurrent access among threads.

Using JavaScript the two different models can be created in the following way:

var xml_doc = new ActiveXObject("Microsoft.XMLDOM");
var xml_ftdoc = new ActiveXObject("Microsoft.FreeThreadedXMLDOM");

And with VBScript:

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
Set objFTXMLDoc = new ActiveXObject("Microsoft.FreeThreadedXMLDOM")

Note:
Documents or nodes created by one method cannot be combined with those created by the other.

A Document is also a Node object, and so inherits various properties and methods from it. For details of the values returned by the nodeName, nodeType and nodeValue properties for a Document, see the Node object.

Properties

async

Syntax: document.async = [true | false]

This property determines whether asynchronous downloading of an XML file is permitted. The default is True, meaning that the load method returns control to the caller before the download is complete. false]

attributes

Syntax: node.attributes

This is a read-only property that returns a NamedNodeMap for nodes that can have attributes.

baseName

Syntax: document.basename

This is a read-only property that returns the base name for a node.

childNodes

Syntax: node.childNodes

This is a read-only property containing a node list of all children for those elements that can have them.

dataType

Syntax: node.dataType

This is a read-only property that specifies the data type for the node.

definition

Syntax: node.definition

This property returns the definition of the node in the DTD or schema.

doctype

Syntax: document.doctype

This is a read-only property that contains the document type node that specifies the DTD for the document.

documentElement

Syntax: document.documentElement

This property contains the root element for the document.

firstChild

Syntax: node.firstChild

This is a read-only property that returns the first child node of a node. If there is none, it returns null.

implementation

Syntax: document.implementation

This is a read-only property that contains the DOMImplementation object for the document. (A DOM application can use objects from multiple implementations.)

lastChild

Syntax: node.lastChild

This is a read-only property that returns the last child node of a node. If there is none, it returns null.

namespaceURI

Syntax: object.namespaceURI

This property is read-only and returns the URI (Universal Resource Indentifier) of the namespace.

nextSibling

Syntax: node.nextSibling

This property returns the next node in the parent's child list, or null if there is none or the node is of a type that cannot be a child node (Attr, Document, DocumentFragment).

nodeName

Syntax: node.nodeName

This property is read-only and contains the name of the node, depending on type.

nodeType

Syntax: node.nodeType

This property is read-only and contains the name of the node, depending on type.

nodeTypedValue

Syntax: node.nodeTypedValue

This property contains the value of this node expressed in its defined data type.

nodeTypeString

Syntax: node.nodeTypeString

This property is read-only and returns the node type in string form.

nodeValue

Syntax: node.nodeValue

This property contains the value of the node, depending on type.

ondataavailable

Syntax: object.ondataavailable

This property is write-only, and specifies the event handler for the ondataavailable event.

onreadystatechange

Syntax: object.onreadystatechange

This property is write-only, and specifies the event handler for the onreadystatechange event.

ontransformnode

Syntax: object.ontransformnode

This property is write-only, and specifies the event handler for the ontransformnode event.

ownerDocument

Syntax: node.ownerDocument

This property returns the Document object to which the node belongs. If the node itself is a document, then it returns null.

parentNode

Syntax: node.parentNode

This is a read-only property that returns the parent node of all nodes except Document, DocumentFragment and Attr, which cannot have parent nodes.

parsed

Syntax: node.parsed

This property returns a boolean value of true if this node and all of its descendants have been parsed and instantiated. Otherwise it returns false.

parseError

Syntax: document.parseError

This property returns an XMLDOMParseError object containing information about the last parse error. prefix Property This property is read-only and returns the namespace prefix, or an empty string if none is specified. For example, it would return 'xxx' for the element xxx:yyy.

prefix

Syntax: object.prefix

Property This property is read-only and returns the namespace prefix, or an empty string if none is specified. For example, it would return 'xxx' for the element xxx:yyy.

preserveWhiteSpace

Syntax: document.preserveWhiteSpace

This property contains a boolean value of true if default processing preserves white space, or false otherwise. By default it is false.

previousSibling

Syntax: node.previousSibling

This property returns the previous node in the parent's child list, or null if there is none or the node is of a type that cannot be an child node (Attr, Document, DocumentFragment).

readyState

Syntax: document.readyState

This property indicates the current state of the XML document.

resolveExternals

Syntax: document.resolveExternals

This property returns a boolean value indicating whether external definitions (resolvable namespaces, DTD external subsets, and external entity references) are to be resolved at parse time, independent of validation.

specified

Syntax: node.specified

This property returns a boolean value which indicates whether or not this attribute has a value specified in the XML document.

text

Syntax: node.text

This property contains the text content of this node and its subtrees.

url

Syntax: document.url

This property contains the canonicalized URL for the last loaded XML document.

validateOnParse

Syntax: object.validateOnParse

This property contains a boolean value indicating whether this document should be validated by the parser. The default is true. If false, only well-formed XML will be parsed.

xml

Syntax: node.xml

This property contains the XML representation of this node and its descendants.

Methods

abort

Syntax: object.abort

This method aborts an asynchronous download in progress, discarding any portion of the XML tree already built. If the readyState property has a value of COMPLETED, no action is taken and the current document is unchanged.

appendChild

Syntax: node.appendChild(tagName)

This method appends a new child node to the list of children for this node.

cloneNode

Syntax: node.cloneNode(deep)

This method creates a clone node which is an exact replica of this node.

createAttribute

Syntax: document.createAttribute(name)

This method creates an Attr object of the specified name.

createCDATASection

Syntax: document.createCDATASection(data)

This method creates a CDATASection object whose value is the data supplied as the argument.

createComment

Syntax: document.createComment(data)

This method creates a Comment object whose value is the data supplied as the argument.

createDocumentFragment

Syntax: document.createDocumentFragment( )

This method creates an empty DocumentFragment object.

createElement

Syntax: document.createElement(tagName)

This method is used to create a new Element object of the type specified by the tagName argument.

createEntityReference

Syntax: document.createEntityReference(name)

This method creates a new EntityReference object of the specified name.

createNode

Syntax: document.createNode(type, name, nameSpaceURI)

This method creates a node using the specified type, name and namespace.

createProcessingInstruction

Syntax: document.createProcessingInstruction(target, data)

This method creates a ProcessingInstruction object with the specified target name and data string.

createTextNode

Syntax: document.createTextNode(data)

This method creates a new Text object whose value is the data passed as the parameter.

getElementsByTagName

Syntax: document.getElementsByTagName(tagName)

This method returns a NodeList collection of those elements with the tag name specified as the argument.

hasChildNodes

Syntax: node.hasChildNodes

This method is a convenient way to determine whether a node has child nodes, returning true if it has, and false if not.

insertBefore

Syntax: node.insertBefore(newChild, refChild)

This method is used to insert a new child node before an existing one. If no child node exists, the new child node becomes the first.

load

Syntax: document.load(url)

This method loads an XML document from the specified location.

load Method

Syntax: object.load(url)

This method loads an XML document from the specified location

loadXML

Syntax: document.loadXML(xmlString)

This method is used to load an XML document using the supplied string.

nodeFromID

Syntax: object.nodeFromID

This method returns the node for the element whose ID attribute matches the one specified. If there is no match, it returns null. This method was designed to handle ID/IDREF relationships in XML, but does not require an attribute of type IDREF. It can be used generically, similarly to the all collection in DHTML. This method requires the use of a xml-schema or dtd.

removeChild

Syntax: node.removeChild(oldChild)

This method removes the specified node from the list of children and returns it.

replaceChild

Syntax: node.replaceChild(newChild, oldChild)

This method is used to replace one of a node's children with another. It returns the old child.

save

Syntax: document.save(objTarget)

This method saves an XML document to a specified location.

selectNodes

Syntax: node.selectNodes(patternString)

This method creates a NodeList of all matching descendant nodes returned by the specified pattern-matching operation.

selectSingleNode

Syntax: node.selectSingleNode(patternString)

This method returns an object for the first descendant node to match the specified pattern.

transformNode

Syntax: node.transformNode(stylesheet)

This method processes this node and its descendants using the specified XSL stylesheet, and returns the resulting transformation.

transformNodeToObject

Syntax: node.transformNodeToObject(stylesheet, outputObject)

This method processes this node and its descendants using the specified XSL stylesheet, and returns the resulting transformation in the specified object.

Events

ondataavailable

Syntax: JScript Syntax: Document.ondataavailable="myHandlerFunction"

This indicates that XML document data is available.

onreadystatechange

Syntax: JScript Syntax: Document.onreadystatechange="myHandlerFunction"

This indicates when the readyState property changes.

ontransformnode

Syntax: boolean = ontransformnode(nodeCode, nodeData)

This is fired before each node in the XML source is transformed by each node in the stylesheet.

See Also: