Represents the top level of the XML source. Includes members for retrieving and creating all other XML objects.
The following script examples demonstrate how to create the two types of objects.
var objDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var objFTDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0");
The following Microsoft® Visual Basic® examples demonstrate how to create the two types of objects.
Dim objDoc As New Msxml2.DOMDocument50 Dim objFTDoc As New Msxml2.FreeThreadedDOMDocument50
The following C/C++ example creates DOMDocument and queries for the other interfaces.
HRESULT hr;
IXMLDOMDocument2 * pXMLDoc;
IXMLDOMNode * pXDN;
//...
hr = CoInitialize(NULL); 
// Check the return value, hr...
hr = CoCreateInstance(CLSID_DOMDocument50, NULL, CLSCTX_INPROC_SERVER, 
       IID_IXMLDOMDocument2, (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.
| Interface | Usage | 
|---|---|
| IUnknown | DOMDocumentis a wrapper object and each query forDOMDocumentreturns a new wrapper. You should only compareIUnknowninterface pointers. | 
| IConnectionPointContainer | Supports outgoing events ondataavailableandonreadystatechangethroughIPropertyNotifySink::OnChangedandIDispatch::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: DeleteMemberByNameorDeleteMemberByDispID,GetMemberProperties,GetMemberName,GetNextDispID, andGetNameSpaceParent. | 
| IMarshal | Can be used to get a FreeThreadedMarshalerfor 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  | 
| IObjectSafety | When the SetInterfaceSafetyOptionsmethod is called with nonzero safety options, Microsoft® XML Core Services (MSXML) 5.0 for Microsoft Office 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 BindToStorageon the givenIMoniker.Saveis not called; therefore theBindToStorage,IsDirty, andSaveCompletedmethods 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 ITypeInfofor theDOMDocument50. | 
| IStream | You can read and write directly to the document through the IStreamthat is returned. You cannotSeekduring aWriteoperation, and the following methods are not implemented on this stream:SetSize,CopyTo,Commit,Revert,LockRegion,UnlockRegion, andClone. This allows you to build an XML document efficiently by providing chunks of XML and callingWriteon the stream. You can also use this to test the persistence of your current DOM document by calling "xmldoc1.save(xmldoc2)." TheSavemethod uses thisIStreaminterface. | 
Note When the object-creation methods (such ascreateElement) are used on the document, nodes are created in the context of the document (theownerDocumentproperty 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 callinginsertBefore,replaceChild, orappendChild(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.5.0 | Msxml2.FreeThreadedDOMDocument.5.0 | 
| ClassID | 88D969C0-F192-11D4-A65F-0040963251E5 | 88D969C1-F192-11D4-A65F-0040963251E5 | 
| VB Class Name | DOMDocument50 | FreeThreadedDOMDocument50 | 
Note When developing applications, you might typically consider an interface separately from any CoClasses that implement it. For example, theDOMDocumentCoClass implements theIXMLDOMDocumentinterface. Normally, interfaces and CoClasses might be documented separately and used independently of one another. TheIXMLDOMDocumentinterface, however, was not designed to be implemented separately from one of its provided CoClasses/implementations. It should always be implemented with eitherDOMDocumentorDOMDocument2.
MSXML 2.0 and later
Implementation: msxml5.dll, msxml2.lib
Header and IDL files: msxml2.h, msxml2.idl
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button  in the upper-left corner of the page.
 in the upper-left corner of the page.
appendChild Method | createElement Method | DOMDocument Members | insertBefore Method | IXMLDOMNode | ownerDocument Property | replaceChild Method | setAttributeNode Method | Persistence and the DOM