Represents the top level of the XML source. Includes members for retrieving and creating all other XML objects.
If you are writing a single threaded application (or a multi-threaded application where only one thread accesses a DOM at one time), use the rental threaded model (
Msxml2.DOMDocument.6.0). If you are writing an application where multiple threads access will simultaneously access a DOM, use the free threaded model (
The following JScript examples demonstrate how to create the two types of objects.
var objDoc = new ActiveXObject("Msxml2.DOMDocument.6.0"); var objFTDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
The following C/C++ example creates
DOMDocument and queries for the other interfaces.
HRESULT hr; IXMLDOMDocument * pXMLDoc; IXMLDOMNode * pXDN; //... hr = CoInitialize(NULL); // Check the return value, hr... hr = CoCreateInstance(CLSID_DOMDocument30, NULL, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (void**)&pXMLDoc); // Check the return value, hr... hr = pXMLDoc->QueryInterface(IID_IXMLDOMNode, (void **)&pXDN); // Check the return value.
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.
||Supports outgoing events
||Interface used by Visual Basic.|
||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:
||Can be used to get a
||Enables a host application to provide extra contextual information, such the base URL.|
||Used by a COM container to send an OLECMDID_STOP command to stop an asynchronous download.|
||Provides control over how to bind the XML document to persistent data. Both synchronous and asynchronous loading are supported using
||Used to save and load the XML document to and from an
||Updated version of
||Provides an easy way to get
||You can read and write directly to the document through the
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
appendChild (or for attributes,
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.DOMDocument.6.0||Msxml2.FreeThreadedDOMDocument.3.0 / Msxml2.FreeThreadedDOMDocument.6.0|
|ClassID||F6D90F11-9C73-11D3-B32E-00C04F990BB4/ 88d96a05-f192-11d4-a65f-0040963251e5||F6D90F12-9C73-11D3-B32E-00C04F990BB4/ 88d96a06-f192-11d4-a65f-0040963251e5|
|VB Class Name||DOMDocument30 / DOMDocument60||FreeThreadedDOMDocument30 / FreeThreadedDOMDocument60|
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
msxml3.dll, msxml2.lib (MSXML 3.0)
msxml6.dll, msxml6.lib (MSXML 6.0)
Header and IDL files (C/C++): msxml2.h, msxml2.idl, msxml6.h, msxml6.idl
Implemented in: MSXML 3.0, MSXML 6.0
Persistence and the DOM