Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


More information

Steps to Reproduce Behavior

The following example binds a table to an XML data island and dynamically adds a new element named "bio" to the data island through script. However, when the data binding agent first invokes the DSO, no "bio" nodes exist in the tree. Thus, the DSO does not know about the "bio" element, and the table is not updated even after you rebind it to the DSO.
<HTML>
<HEAD>
<TITLE>Run-time binding with XML data island</TITLE>
<script>

function bind1()
{
	  tbl1.dataSrc = "";
	  doc = xml1.XMLDocument;
	  curNode = doc.selectSingleNode("/composers/composer1");
	  txtNode = doc.createTextNode("French composer of piano music");
	  elem = doc.createElement("bio");
	  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 = "#xml1";  
}
</script>


</HEAD>
<BODY>

<XML ID="xml1">
<composers>
	<composer1>
	    <firstname>Claude</firstname>
	    <lastname>Debussy</lastname>
	    <origin>France</origin>
	</composer1>
</composers>
</XML>

<p>
<div style="font:10 pt Verdana"> 
The XML data island that is the datsrc of this table does not 
have an element named "bio". Clicking Update dynamically adds that 
element to the data island and rebinds the table:
</div>
</p>


<p>
<table id=tbl1 datasrc="#xml1" border=1>
	<tr width="100%" style="background-color:'#ffe4b5'; font:'12pt Arial'">
		<td width="20%">FirstName</td>
		<td width="20%">LastName</td>
		<td width="20%">Origin</td>
		<td width="20%">Bio</td>
	</tr>
	<tr>
		<td><span datafld="firstname"></td>
		<td><span datafld="lastname"></td>
		<td><span datafld="origin"></td>
		<td><span datafld="bio"></td>
	</tr>
</table>
</p>
<button onClick="bind1();" id=button1 name=button1>Update</button>
</BODY>
</HTML>
				

↑ Back to the top


References

For more information, see the following Microsoft Web sites:

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB303866, kbprb

↑ Back to the top

Article Info
Article ID : 303866
Revision : 2
Created on : 5/12/2003
Published on : 5/12/2003
Exists online : False
Views : 334