Microsoft KB Archive/325690

= BUG: Data loss occurs when you recursively navigate an XmlDataDocument =

Article ID: 325690

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft ADO.NET 1.1
 * Microsoft ADO.NET 1.0
 * Microsoft .NET Framework Class Libraries 1.0
 * Microsoft .NET Framework Class Libraries 1.1

-



This article was previously published under Q325690



SYMPTOMS
When you try to recursively navigate an XmlDataDocument that has been synchronized with a filled ADO.NET DataSet, all of the data is not returned.



CAUSE
A problem exists in the XmlDataDocument implementation of the RTM release of the Microsoft .NET Framework.



RESOLUTION
To work around this problem, access the InnerText property of the XmlDataDocument object before you recursively navigate it. You can also use the GetXml method of the DataSet object to load the XML representation of the DataSet data in an XmlDocument object and navigate it recursively.



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

This will be fixed in the next major version release of the .NET Framework.



Steps to Reproduce the Behavior
 Create a new Microsoft Visual Basic .NET console application.  Replace the code in Module1.vb with the following:NOTE: This sample requires that you have the Northwind sample database installed on a computer that is running Microsoft SQL Server. Modify the connection string to suit your environment. Imports System.Data Imports System.Data.SqlClient Imports System.Xml

Module Module1

Sub Main

Dim dsCustomers As New DataSet dsCustomers.DataSetName = &quot;CustomerData&quot;

' Connect to the Northwind database on the local SQL Server. Dim sqlConn As String = &quot;server=.;&quot; sqlConn += &quot;Integrated Security=SSPI;&quot; sqlConn += &quot;Initial Catalog=Northwind&quot;

' Fill a DataSet with some customer data. Dim selectText As String selectText = &quot;SELECT CustomerID, CompanyName&quot; selectText += &quot; City, Country FROM Customers WHERE CustomerID='ANATR'&quot;

Dim cmdCustomers As SqlDataAdapter = New SqlDataAdapter(selectText, sqlConn) cmdCustomers.Fill(dsCustomers, &quot;Customers&quot;)

' Synchronize the DataSet with XmlDataDocument. Dim xmlDoc As New XmlDataDocument(dsCustomers)

'PROBLEM: Try to access XmlDataDocument's content. Console.WriteLine(&quot;Output generated by recursively navigating the XmlDataDocument&quot; & vbNewLine) renderNode(xmlDoc)

'WORKAROUND: Accessing the XmlDataDocument's InnerText property using code 'identical to the following renders the data correctly. Dim dummy As String = xmlDoc.InnerText Console.WriteLine(vbNewLine & vbNewLine & &quot;Output generated by recursively navigating&quot; & _        &quot; the XmlDataDocument AFTER accessing its InnerText property&quot; & vbNewLine) renderNode(xmlDoc) Console.ReadLine End Sub

Sub renderNode(ByVal inNode As XmlNode) Dim node As XmlNode For Each node In inNode.ChildNodes If node.NodeType = XmlNodeType.Element Then Console.WriteLine(&quot;Element Node: &quot; & node.Name) End If        If node.NodeType = XmlNodeType.Text Then Console.WriteLine(&quot;Text Node: &quot; & node.Value) End If        If node.HasChildNodes Then renderNode(node) End If     Next End Sub

End Module   Compile and run the application. The output is similar to the following: Output generated by recursively navigating the XmlDataDocument

Element Node: CustomerData Element Node: Customers

Output generated by recursively navigating the XmlDataDocument AFTER accessing its InnerText property

Element Node: CustomerData Element Node: Customers Element Node: CustomerID Text Node: ANATR Element Node: City Text Node: Ana Trujillo Emparedados y helados Element Node: Country Text Node: Mexico 

