BUG: DSO Recordset Pointer Is Corrupted If You Use the XML DSO LoadXml Method in Window_onLoad() (290194)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q290194

SYMPTOMS

If you use the LoadXml method of the Internet Explorer 5.5 XML Data Source object (DSO) to initialize its recordset structure and delete the initial record(s) in the Window_onLoad event procedure, the recordset pointer of the DSO is corrupted. The RecordCount property of the DSO's recordset appears as zero even after you add new records to it.

This problem is specific to the Internet Explorer 5.5 XML DSO and does not occur in Internet Explorer 5.

RESOLUTION

To work around this problem, use one of the following methods:
  • Specify the XML that is required to initialize the DSO's recordset structure within the DSO's <XML> tag.
  • Persist the XML that is required to initialize the recordset structure in an external file, and reference it in the DSO's <XML> tag with the SRC attribute.
For code that demonstrates these workarounds, see the "More Information" section.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. In Notepad, create a new HTML file named DSOBug.html, and paste the following code:
    <HTML>
    <BODY>
    
    <SCRIPT Language="VBScript">
    Sub Window_onLoad()
    xmlDSO.loadxml "<Books><Book><Title>Beginning XML</Title>" & _
                   "<Publisher>Wrox</Publisher></Book></Books>"
       xmlDSO.Recordset.Delete      
    End Sub
    
    Sub AddBook()
      xmlDSO.Recordset.AddNew
      xmlDSO.Recordset.Fields("Title") = "XML Step By Step"
      xmlDSO.Recordset.Fields("Publisher") = "MS Press"
      xmlDSO.Recordset.Update
      MsgBox "Recordcount after AddNew : " & xmlDSO.Recordset.recordcount 
    End Sub
    
    </SCRIPT>
    
    <XML id="xmlDSO">
    </XML>
    
    <TABLE id="tabBooks" DATASRC="#xmlDSO" border=1>
      <TR>
       <TD><span datafld="Title"></span></TD>
       <TD><span datafld="Publisher"></span></TD>
     </TR>
    </TABLE>
    
    <BR>
    <INPUT type=button value="Add Record" onClick="AddBook">
    
    </BODY>
    </HTML>
    
    					
  2. Save DSOBug.html to your hard disk.
  3. In Internet Explorer 5.5, browse to DSOBug.html. When the page loads in the browser, the code in the Window_onLoad event procedure uses an XML string to run the LoadXml method of the XML DSO to initialize its recordset structure. In the call to the LoadXml method, the initial single record that is loaded into the DSO's recordset is deleted.
  4. On the HTML page, click Add Record to add a record to the DSO and display the RecordCount property of its recordset. Notice that the newly added record is displayed in the HTML table bound to the DSO, and that the RecordCount property of the DSO's recordset is displayed incorrectly as zero.

Workaround 1

  1. In Notepad, open DSOBug.html.
  2. Comment out the following statement in the Window_onLoad event procedure:
    'xmlDSO.loadxml "<Books><Book><Title>Beginning XML</Title>" & _
    '               "<Publisher>Wrox</Publisher></Book></Books>"
    					
  3. Modify the DSO's <XML> tag and its contents as follows to specify the XML that is used to initialize the DSO's recordset structure:
    <XML id="xmlDSO">
    <Books>
      <Book>
          <Title>Beginning XML</Title>
          <Publisher>Wrox</Publisher>
      </Book>
    </Books>
    </XML>
    					
  4. In Internet Explorer, browse to DSOBug.html. Click Add Record to add a new record to the DSO's recordset. Notice that the newly added record is displayed in the HTML table bound to the DSO, and that the RecordCount property of the DSO's recordset is displayed correctly.

Workaround 2

  1. In Notepad, open DSOBug.html.
  2. Comment out the following statement in the Window_onLoad event procedure:
    'xmlDSO.loadxml "<Books><Book><Title>Beginning XML</Title>" & _
    '               "<Publisher>Wrox</Publisher></Book></Books>"
    					
  3. In Notepad, create a new XML file named Data.xml, and paste the following code, which is used to initialize the DSO's recordset structure:
    <Books>
      <Book>
          <Title>Beginning XML</Title>
          <Publisher>Wrox</Publisher>
      </Book>
    </Books>
    					
  4. Save Data.xml in the same folder as DSOBug.html.
  5. Modify the DSO's <XML> tag in DSOBug.html as follows to reference Data.xml using its SRC attribute:
    <XML id="xmlDSO" SRC="Data.xml">
    </XML>
    					
  6. In Internet Explorer, browse to DSOBug.html. Click Add Record to add a new record to the DSO's recordset. Notice that the newly added record is displayed in the HTML table bound to the DSO, and that the RecordCount property of the DSO's recordset is displayed correctly.

Modification Type:MajorLast Reviewed:9/30/2003
Keywords:kbBug kbDHTML kbMSXMLnosweep kbpending KB290194