When you bind HTML elements to the Internet Explorer XML Data Source Object (DSO) and delete its initial records in the Window_onLoad event procedure, the DSO's Recordset pointer is corrupted. The recordcount property of the DSO's Recordset remains zero even after new records are added to it.
↑ Back to the top
This problem occurs only when you use scripting code in the Window_onLoad event procedure to bind the HTML elements to the XML DSO at run time. To work around this problem, set the DATASRC and DATAFLD Dynamic HTML (DHTML) attributes in their HTML tags to bind HTML elements to the XML DSO. For a step-by-step example, see the "More Information" section.
↑ Back to the top
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
↑ Back to the top
Steps to Reproduce Behavior
- In Notepad, create a new file, and paste the following HTML code:
<HTML>
<BODY>
<SCRIPT Language="VBScript">
Sub Window_onLoad()
tabBooks.datasrc="#xmlDSO"
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">
<Books>
<Book>
<Title>Beginning XML</Title>
<Publisher>Wrox</Publisher>
</Book>
</Books>
</XML>
<TABLE id="tabBooks" 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>
- Save the file to your hard disk drive as DSOBug.html.
- Open DSOBug.html in Internet Explorer. When the page loads in the browser, the code in the Window_onLoad event procedure binds the XML DSO that is included in the page to the HTML "tabBooks" table and deletes the initial single record in the DSO's Recordset.
- Click Add Record on the HTML page to add a record to the DSO and display the recordcount property of its Recordset. Note that the newly added record is displayed in the HTML table and that the recordcount of the DSO's Recordset is displayed incorrectly as zero.
Workaround
- In Notepad, open DSOBug.html.
- Comment out the following statement in the Window_onLoad() event procedure:
'tabBooks.datasrc="#xmlDSO"
- Modify the <TABLE> HTML element to implement the data binding by including the DATASRC attribute and setting it to the name of the XML DSO in the following code:
<TABLE id="tabBooks" DATASRC="#xmlDSO" border=1>
<TR>
<TD><span datafld="Title"></span></TD>
<TD><span datafld="Publisher"></span></TD>
</TR>
</TABLE>
- In Internet Explorer, open DSOBug.html, and 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 and that the recordcount of the DSO's Recordset is correctly displayed as 1.
↑ Back to the top