IXMLDOMDocument/DOMDocument

 

Description

 

Represents the top level of the XML source. Includes members for retrieving and creating all other XML objects.

 

In addition to the DOM interfaces, DOMDocument implements a number of standard COM interfaces. You can call the QueryInterface method on DOMDocument to get the following interfaces.

 

Interface

Usage

IUnknown

DOMDocument is a wrapper object and each query for DOMDocument returns a new wrapper. You should only compare IUnknown interface pointers.

IConnectionPointContainer

Supports outgoing events ondataavailable and onreadystatechange through IPropertyNotifySink.OnChanged and IDispatch.Invoke.

IDispatch

Interface used by Visual Basic.

IDispatchEx

Interface used by dynamic late-bound scripting languages such as Microsoft Visual Basic Scripting Edition (VBScript) and Microsoft JScript®. This is not fully implemented. The following methods always return E_NOTIMPL: DeleteMemberByName or DeleteMemberByDispID, GetMemberProperties, GetMemberName, GetNextDispID, and GetNameSpaceParent.

IMarshal

Can be used to get a FreeThreadedMarshaler for a free-threaded DOM document. This allows the free-threaded DOM document to be used in Active Server Pages (ASP) shared Session and Application states for sharing XML documents across multiple clients in memory.

Note In MSXML, "free-threaded" means ThreadingModel='Both', and cross-thread marshalling is supported.

IObjectSafety

When the SetInterfaceSafetyOptions method is called with nonzero safety options, Microsoft XML Core Services (MSXML) will apply security rules before fetching XML data.

IObjectWithSite

Enables a host application to provide extra contextual information, such the base URL.

IOleCommandTarget

Used by a COM container to send an OLECMDID_STOP command to stop an asynchronous download.

IPersistMoniker

Provides control over how to bind the XML document to persistent data. Both synchronous and asynchronous loading are supported using BindToStorage on the given IMoniker. Save is not called; therefore the BindToStorage, IsDirty, and SaveCompleted methods return E_NOTIMPL.

IPersistStream

Used to save and load the XML document to and from an IStream.

IPersistStreamInit

Updated version of IPersistStream.

IProvideClassInfo

Provides an easy way to get ITypeInfo for a DOM document.

IStream

You can read and write directly to the document through the IStream that is returned. You cannot Seek during a Write operation, and the following methods are not implemented on this stream: SetSize, CopyTo, Commit, Revert, LockRegion, UnlockRegion, and Clone. This allows you to build an XML document efficiently by providing chunks of XML and calling Write on the stream. You can also use this to test the persistence of your current DOM document by calling "xmldoc1.save(xmldoc2)." The Save method uses this IStream interface.

 

Remarks

 

Note When the object-creation methods (such as createElement) are used on the document, nodes are created in the context of the document (the ownerDocument property of the node points to the document), but the node is not part of the document tree. The node is only part of the document tree when it is explicitly added to the tree by calling insertBefore, replaceChild, or appendChild (or for attributes, setAttributeNode).

 

DOMDocument represents the top node in the tree. It implements all of the base Document Object Model (DOM) document methods and provides additional members that support Extensible Stylesheet Language (XSL) and XML transformations.

 

Only one object can be created: the document. All other objects are accessed or created from the document.

 

The document can be created using either a free-threaded or a rental-threaded model. The behavior of the two models is identical; rental-threaded documents exhibit better performance because the parser does not need to manage concurrent access among threads. You cannot combine nodes or documents that are created using differing threading models. The document threading model is determined by the following settings.

 

Setting

Rental-threaded model

Free-threaded model

ProgID

Msxml2.DOMDocument.3.0

Msxml2.FreeThreadedDOMDocument.3.0

ClassID

F6D90F11-9C73-11D3-B32E-00C04F990BB4

F6D90F12-9C73-11D3-B32E-00C04F990BB4

VB Class Name

DOMDocument30

FreeThreadedDOMDocument30

 

Note When developing applications, you might typically consider an interface separately from any CoClasses that implement it. For example, the DOMDocument CoClass implements the IXMLDOMDocument interface. Normally, interfaces and CoClasses might be documented separately and used independently of one another. The IXMLDOMDocument interface, however, was not designed to be implemented separately from one of its provided CoClasses/implementations. It should always be implemented with either DOMDocument or DOMDocument2.

 

Versioning

 

Implemented in: MSXML 2.0 and later

 

IXMLDOMDocument/DOMDocument Members

 

The following tables show the properties, methods, and events.

 

In C++, this interface inherits from IXMLDOMNode.

 

Properties

 

async*

Specifies if asynchronous download is permitted. Read/write.

attributes

Contains the list of attributes for this node. Read-only.

baseName*

Returns the base name for the name qualified with the namespace. Read-only.

childNodes

Contains a node list containing the children nodes. Read-only.

dataType*

Specifies the data type for this node. Read/write.

definition*

Returns the definition of the node in the document type definition (DTD) or schema. Read-only.

doctype

Contains the document type node that specifies the DTD for this document. Read-only.

documentElement

Contains the root element of the document. Read/write.

firstChild

Contains the first child of this node. Read-only.

implementation

Contains the IXMLDOMImplementation object for the document. Read-only.

lastChild

Returns the last child node. Read-only.

namespaceURI*

Returns the Uniform Resource Identifier (URI) for the namespace. Read-only.

nextSibling

Contains the next sibling of the node in the parent's child list. Read-only.

nodeName

Returns the qualified name for attribute, document type, element, entity, or notation nodes. Returns a fixed string for all other node types. Read-only.

nodeType

Specifies the XML Document Object Model (DOM) node type, which determines valid values and whether the node can have child nodes. Read-only.

nodeTypedValue*

Contains this node's value expressed in its defined data type. Read/write.

nodeTypeString*

Returns the node type in string form. Read-only.

nodeValue

Contains the text associated with the node. Read/write.

ondataavailable*

Specifies the event handler for the ondataavailable event. Write-only.

onreadystatechange*

Specifies the event handler to be called when the readyState property changes. Write-only.

ontransformnode*

Specifies the event handler for the ontransformnode event. Write-only.

ownerDocument

Returns the root of the document that contains this node. Read-only.

parentNode

Contains the parent node. Read-only.

parsed*

Indicates the parsed status of the node and child nodes. Read-only.

parseError*

Returns an IXMLDOMParseError object that contains information about the last parsing error. Read-only.

prefix*

Returns the namespace prefix. Read-only.

preserveWhiteSpace*

Specifies the default white space handling. Read/write.

previousSibling

Contains the previous sibling of the node in the parent's child list. Read-only.

readyState*

Indicates the current state of the XML document. Read-only.

resolveExternals*

Indicates whether external definitions (resolvable namespaces, DTD external subsets, and external entity references) are to be resolved at parse time, independent of validation. Read/write.

specified*

Indicates whether the node (usually an attribute) is explicitly specified or derived from a default value in the DTD or schema. Read-only.

text*

Represents the text content of the node or the concatenated text representing the node and its descendants. Read/write.

url*

Returns the URL for the last loaded XML document. Read-only.

validateOnParse*

Indicates whether the parser should validate this document. Read/write.

xml*

Contains the XML representation of the node and all its descendants. Read-only.

 

* Denotes an extension to the World Wide Web Consortium (W3C) DOM.

 

Methods

 

abort*

Aborts an asynchronous download in progress.

appendChild

Appends a new child as the last child of this node.

cloneNode

Clones a new node.

createAttribute

Creates a new attribute with the specified name.

createCDATASection

Creates a CDATA section node that contains the supplied data.

createComment

Creates a comment node that contains the supplied data.

createDocumentFragment

Creates an empty IXMLDOMDocumentFragment object.

createElement

Creates an element node using the specified name.

createEntityReference

Creates a new EntityReference object.

createNode*

Creates a node using the supplied type, name, and namespace.

createProcessingInstruction

Creates a processing instruction node that contains the supplied target and data.

createTextNode

Creates a text node that contains the supplied data.

getElementsByTagName

Returns a collection of elements that have the specified name.

hasChildNodes

Provides a fast way to determine whether a node has children.

insertBefore

Inserts a child node to the left of the specified node or at the end of the list.

load*

Loads an XML document from the specified location.

loadXML*

Loads an XML document using the supplied string.

nodeFromID*

Returns the node that matches the ID attribute.

removeChild

Removes the specified child node from the list of children and returns it.

replaceChild

Replaces the specified old child node with the supplied new child node.

save*

Saves an XML document to the specified location.

selectNodes*

Applies the specified pattern-matching operation to this node's context and returns the list of matching nodes as IXMLDOMNodeList.

selectSingleNode*

Applies the specified pattern-matching operation to this node's context and returns the first matching node.

transformNode*

Processes this node and its children using the supplied XSLT style sheet and returns the resulting transformation.

transformNodeToObject*

Processes this node and its children using the supplied XSLT style sheet and returns the resulting transformation in the supplied object.

 

* Denotes an extension to the W3C DOM.

 

Events

 

ondataavailable*

Fires when new data is available.

onreadystatechange*

Fires when the readyState property changes.

ontransformnode*

Fires before the style sheet is applied to a node.

 

* Denotes an extension to the W3C DOM.

 

Valid XHTML 1.0 Transitional