IXMLDOMDocument/DOMDocument

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

IXMLDOMDocument/DOMDocument

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

[Script]

Example

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");
[Visual Basic]

Example

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
[C/C++]

Example

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 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) 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 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 the DOMDocument50.
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.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, 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

MSXML 2.0 and later

Requirements

Implementation: msxml5.dll, msxml2.lib

[C/C++]

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 Language Filter in the upper-left corner of the page.

See Also

appendChild Method | createElement Method | DOMDocument Members | insertBefore Method | IXMLDOMNode | ownerDocument Property | replaceChild Method | setAttributeNode Method | Persistence and the DOM