Microsoft KB Archive/303866

= PRB: Element Is Not Updated When You Add Data to an XML Data Island =

Article ID: 303866

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer (Programming) 5.01 SP1
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q303866



SYMPTOMS
When you bind an element to XML data and dynamically add more data to the data island through script, the Data Source Object (DSO) is not updated. As a result, the element cannot display the newly added data.

This problem is not specific to the XML data island; it applies to other data sources as well.



CAUSE
This problem occurs because the DSO determines the schema of the data when the data binding agent first invokes it. Even if you add more data to the source later, the DSO cannot change the schema. Therefore, the element that is binding to the DSO fails to display the updated data.



RESOLUTION
To resolve this problem, follow these steps:
 * 1) Call loadXML on the XML DSO with the updated data island to reload the XML DSO.
 * 2) Add an empty element statically to allow Internet Explorer to construct the schema.
 * 3) Remove the element programmatically when it loads. After you do so, the schema builder sees the element, and you can dynamically add attributes and text to the element later without any problem.



Steps to Reproduce Behavior
The following example binds a table to an XML data island and dynamically adds a new element named &quot;bio&quot; to the data island through script. However, when the data binding agent first invokes the DSO, no &quot;bio&quot; nodes exist in the tree. Thus, the DSO does not know about the &quot;bio&quot; element, and the table is not updated even after you rebind it to the DSO.   Run-time binding with XML data island

function bind1 {     tbl1.dataSrc = &quot;&quot;; doc = xml1.XMLDocument; curNode = doc.selectSingleNode(&quot;/composers/composer1&quot;); txtNode = doc.createTextNode(&quot;French composer of piano music&quot;); elem = doc.createElement(&quot;bio&quot;); elem.appendChild(txtNode); curNode.appendChild(elem); // This shows that the data island has been updated with the // new data. alert(xml1.xml);

// The following line reloads the data from the XML data island // into the DSO. Uncomment this line for the code to work properly. // xml1.loadXML(xml1.xml); tbl1.dataSrc = &quot;#xml1&quot;; }

 

 Claude Debussy France 

 The XML data island that is the datsrc of this table does not have an element named &quot;bio&quot;. Clicking Update dynamically adds that element to the data island and rebinds the table:

Update  </HTML>

<div class="references_section">