Compartilhar via


IXMLDOMDocument-DOMDocument

 

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.3.0 or Msxml2.DOMDocument.6.0). If you are writing an application where multiple threads access will simultaneously access a DOM, use the free threaded model (Msxml2.FreeThreadedDOMDocument.3.0 or Msxml2.FreeThreadedDOMDocument.6.0).

JScript Examples

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");  
  

C/C++ Examples

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.

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.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

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.

Requirements

Implementation:

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

Versioning

Implemented in: MSXML 3.0, MSXML 6.0

See Also

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