FIX: Loss of Data Results If You Replace the DocumentElement Property of the XML DSO (262620)



The information in this article applies to:

  • Microsoft XML 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:

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

The following steps recreate the behavior:
  1. 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>
    					
  2. Save the file as Testdso.htm in a folder on your hard drive.
  3. 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.
  4. Open Testdso.htm in the browser. The data contained in xmlPeople is displayed in an HTML table bound to the data island.
  5. 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.
  6. 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.
  7. 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.

REFERENCES

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 INFO: Version List of the Microsoft XML Parser


Modification Type:MajorLast Reviewed:10/15/2002
Keywords:kbBug kbDSupport KB262620