Microsoft KB Archive/262620

= FIX: Loss of Data Results If You Replace the DocumentElement Property of the XML DSO =

Article ID: 262620

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft XML Parser 2.0

-



This article was previously published under Q262620



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



RESOLUTION
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:

http://msdn.microsoft.com/xml/default.asp



STATUS
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:

 Sub ChangeDocElem Msgbox &quot;Records in xmlPeople before replacing documentElement : &quot; & xmlPeople.recordset.recordcount set xmlPeople.documentElement = xmlEmployees.documentElement Msgbox &quot;Records in xmlPeople after replacing documentElement : &quot; & xmlPeople.recordset.recordcount End Sub 

   John 727-879-8765 <Email>john@xyz.com</Email> </Person> </People>

<xml id=&quot;xmlEmployees&quot;> <Employees> <Employee> John</Name> 727-879-8765</Phone> <Email>john@xyz.com</Email> </Employee> <Employee> Jack</Name> 727-879-8765</Phone> <Email>jack@xyz.com</Email> </Employee> </Employees>

<H3>List of People</H3><BR>

<input id=&quot;ChangeDocElem&quot; type=&quot;Button&quot; value=&quot;Change Document Element of xmlPeople&quot;  onClick=&quot;ChangeDocElem&quot;>

</li> <li>Save the file as Testdso.htm in a folder on your hard drive.</li> <li>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.</li> <li>Open Testdso.htm in the browser. The data contained in xmlPeople is displayed in an HTML table bound to the data island.</li> <li>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.</li> <li>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.</li> <li>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.</li></ol>

<div class="references_section">