Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 262620 - Last Review: October 15, 2002 - Revision: 1.3
FIX: Loss of Data Results If You Replace the DocumentElement Property of the XML DSO
This article was previously published under Q262620
If you replace the
documentElement property of an XML Data Source Object (DSO) in script code at run time, a loss of data occurs. If you run a statement such as
Set xmlDSO1.DocumentElement = xmlDSO2.DocumentElement, records are deleted in the recordset of the target DSO. This means that the target DSO is not rebuilt to contain the records in the recordset of the source DSO.
This problem has been fixed in the Microsoft XML (MSXML) 2.5 parser.
To obtain this parser, select
XML Downloads on the following Microsoft Web site at:
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
Steps to Reproduce Behavior
The following steps recreate the behavior:
- Copy and paste the following code into a new file in Microsoft Notepad:
<html>
<body>
<SCRIPT Language="VBScript">
Sub ChangeDocElem()
Msgbox "Records in xmlPeople before replacing documentElement : " & xmlPeople.recordset.recordcount
set xmlPeople.documentElement = xmlEmployees.documentElement
Msgbox "Records in xmlPeople after replacing documentElement : " & xmlPeople.recordset.recordcount
End Sub
</SCRIPT>
<xml id="xmlPeople">
<People>
<Person>
<Name>John</Name>
<Phone>727-879-8765</Phone>
<Email>john@xyz.com</Email>
</Person>
</People>
</xml>
<xml id="xmlEmployees">
<Employees>
<Employee>
<Name>John</Name>
<Phone>727-879-8765</Phone>
<Email>john@xyz.com</Email>
</Employee>
<Employee>
<Name>Jack</Name>
<Phone>727-879-8765</Phone>
<Email>jack@xyz.com</Email>
</Employee>
</Employees>
</xml>
<H3>List of People</H3><BR>
<table datasrc=#xmlpeople border=1>
<thead>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
</thead>
<tr>
<td><div datafld="Name"></div></td>
<td><div datafld="Phone"></div></td>
<td><div datafld="Email"></div></td>
</tr>
</table>
<p><input id="ChangeDocElem" type="Button" value="Change Document Element of xmlPeople" onClick="ChangeDocElem">
</body>
</html>
- Save the file as Testdso.htm in a folder on your hard drive.
- The code in the preceding sample defines two XML data islands, xmlPeople and xmlEmployees. The PERSON and EMPLOYEE elements in the two data islands are defined with an identical set of attributes. An XML DSO binds the xmlPeople data island to an HTML table.
- Open Testdso.htm in the browser. The data contained in xmlPeople is displayed in an HTML table bound to the data island.
- Click the Change Document Element of xmlPeople BUTTON element to run the code in the ChangeDocElem sub procedure. The code in this procedure assigns the recordset of the xmlEmployees data island to the xmlPeople data island. Additionally, it displays the number of records in the recordset object of the xmlPeople data islands before and after it runs the assignment.
- Run this code on a computer with the MSXML 2.0 parser to delete the records that are contained in the recordset object of the xmlPeople data island. After the assignment is run, the Msgbox statement displays the recordcount of the xmlPeople data island's recordset as 0, and the data rows in the HTML table bound to xmlPeople are deleted.
- Run the code with the MSXML 2.5 parser to assign the recordset of the xmlEmployee's data island to the xmlPeople's data island. After the assignment is run, the Msgbox statement displays the recordcount of the xmlPeople data island's recordset as 2 (the number of Employee elements in the xmlEmployees data island), and the HTML table bound to xmlPeople displays the records contained in the xmlEmployees data island as required.
For additional information about the different versions of the MSXML parsers released to date and their shipping products, click the article number below
to view the article in the Microsoft Knowledge Base:
269238Â
(http://kbalertz.com/Feedback.aspx?kbNumber=269238/EN-US/
)
INFO: Version List of the Microsoft XML Parser
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