Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 284856 - Last Review: October 12, 2001 - Revision: 1.0
PRB: Mixing Different Versions of MSXML DOM Objects Is Not Recommended
This article was previously published under Q284856
On This Page
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.
MORE INFORMATION
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 "Symptoms" 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 "<Books><Book>XML Programming</Book></Books>"
Set node26 = doc26.childNodes(0)
Dim doc30 As Object
Set doc30 = CreateObject("MSXML2.DOMDocument.3.0")
node26.appendChild doc30.createNode(NODE_ELEMENT, "Book", "")
MsgBox doc26.xml
- 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.
- 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
- Stop the execution of the project.
- Add a second CommandButton to Form1 and label it Error 2.
- Open an empty text file in Microsoft Notepad.
- Copy and paste the following XML code into Notepad and save the file as books.xml in the folder of your choice:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="books.xsl"?>
<books>
<book>
<title>XML Step by Step</title>
</book>
<book>
<title>Mastering XML</title>
</book>
</books>
- Open another empty file in Notepad.
- 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="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="books">
<html>
<body>
<h1>A list of books</h1>
<table>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<tr>
<td><xsl:value-of select="./title"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
- 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 "<path to books.xml>"
Set xsldoc = CreateObject("MSXML2.DOMDocument.3.0")
xsldoc.Load "<path to books.xsl>"
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.
- 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
APPLIES TO
- Microsoft XML Parser 2.0
- Microsoft XML Parser 2.5
- Microsoft XML Parser 2.6
- Microsoft XML Parser 3.0
- Microsoft XML Core Services 4.0
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please