Microsoft KB Archive/284856

= PRB: Mixing Different Versions of MSXML DOM Objects Is Not Recommended =

Article ID: 284856

Article Last Modified on 10/12/2001

-

APPLIES TO


 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q284856



SYMPTOMS
The Microsoft XML (MSXML) Document Object Model (DOM) objects exposed by the MSXML parser can be used to programmatically create, load, and manipulate XML documents. Avoid mixing DOM objects from different versions of the MSXML parser because it is not a recommended coding practice. If you attempt to mix different versions of the MSXML DOM objects while programming the DOM, one of the following error messages appears:

Run-time error '-2147024809(80070057)': The parameter is incorrect

Run-time error '-2147467262(80004002)': No such interface supported



CAUSE
When you mix different versions of MSXML DOM objects in a DOM object's method call, the object from the differing version of the parser that is supplied as a required method parameter is treated as a foreign object.



RESOLUTION
Reference and use objects implemented by a single version of the MSXML parser. Do not mix different versions of DOM Objects when you program the MSXML DOM.



Steps to Reproduce Behavior
Execute the following steps to set up a Microsoft Visual Basic sample that reproduces the error messages that appear in the &quot;Symptoms&quot; section of this article. The code in the sample uses versions 2.6 and 3.0 of the MSXML parser. You need to have both versions of the MSXML parser installed on your computer to reuse the code without modifying the ProgIDs of the DOM objects. You may also reproduce the behavior mixing MSXML version 2.6 with 4.0, 3.0 with 4.0, and so on.  Create a new Standard EXE project in Visual Basic 6.0. Form1 is created by default. On the Project menu, set a reference to Microsoft XML v2.6. Add a CommandButton on Form1 and label the button Error 1.  Copy and paste the following code into the Click event procedure of Error 1: Dim doc26 As MSXML2.DOMDocument26 Dim node26 As MSXML2.IXMLDOMNode

Set doc26 = New MSXML2.DOMDocument26 doc26.loadXML &quot;XML Programming</Books>&quot;

Set node26 = doc26.childNodes(0)

Dim doc30 As Object Set doc30 = CreateObject(&quot;MSXML2.DOMDocument.3.0&quot;) node26.appendChild doc30.createNode(NODE_ELEMENT, &quot;Book&quot;, &quot;&quot;)

MsgBox doc26.xml </li> The preceding code loads well-formed XML into an instance of an MSXML 2.6 DOMDocument object. It then attempts to append an MSXML 3.0 IXMLDOMNode object to a child node of the MSXML 2.6 DOMDocument.</li> Save and run the project. Click Error 1 to generate the following error message on the node26.appendChild statement:

Run-time error '-2147024809(80070057)': The parameter is incorrect

</li> Stop the execution of the project.</li> Add a second CommandButton to Form1 and label it Error 2.</li> Open an empty text file in Microsoft Notepad.</li>  Copy and paste the following XML code into Notepad and save the file as books.xml in the folder of your choice: <?xml version=&quot;1.0&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;books.xsl&quot;?> XML Step by Step Mastering XML </li> Open another empty file in Notepad.</li>  Copy and paste the following XSL code into Notepad and save the file as books.xsl in the same folder where you saved books.xml: <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;>

<xsl:template match=&quot;books&quot;> A list of books </xsl:template>

<xsl:template match=&quot;book&quot;> <xsl:value-of select=&quot;./title&quot;/> </xsl:template>

</xsl:stylesheet> </li>  Copy and paste the following code into the Click event procedure of the Error 2: Dim xmldoc As MSXML2.DOMDocument26 Dim xsldoc As Object

Set xmldoc = New MSXML2.DOMDocument26 xmldoc.Load &quot;<path to books.xml>&quot;

Set xsldoc = CreateObject(&quot;MSXML2.DOMDocument.3.0&quot;) xsldoc.Load &quot;<path to books.xsl>&quot;

Debug.Print xmldoc.transformNode(xsldoc) In the preceding code, you need to insert the paths to books.xml and books.xsl in the statements that load the XML and XSL documents into two instances of the DOMDocument object.

This code loads the XML document into an instance of the MSXML 2.6 DOMDocument object. It then loads the XSL document into an instance of the MSXML 3.0 DOMDocument object and attempts to execute the XSL transform by mixing the DOMDocument objects from the two different versions of the MSXML parser.

</li> Save and run the project. Click Error 2 to generate the following error message from the transformNode method of the MSXML 2.6 DOMDocument object:

Run-time error '-2147467262(80004002)': No such interface supported

</li></ol>

Additional query words: -2147024809 -2147467262 80004002 80070057 -2147024809(80070057) -2147467262(80004002)

Keywords: kbprb KB284856

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.