Microsoft KB Archive/318148

= BUG: Synchronization is not performed on DataSet and XmlDataDocument when you set InnerXml on a text node =

Article ID: 318148

Article Last Modified on 9/15/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft .NET Framework Class Libraries 1.1
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q318148



SYMPTOMS
Synchronization between DataSet(System.Data) and XmlDataDocument(System.Xml) is not performed when you use InnerXml on a node that has a text node only. The text appears to disappear from the output that is generated.



RESOLUTION
Instead of directly modifying the innerText property of the node, set the required node to an XmlNode object, and then modify the innerText property.



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



Steps to Reproduce the Behavior
  Use Notepad to create a new XML document that contains the following code:   Zero 0  Zero 0</colInt> </MyTable2> </MyTable1> <MyTable1 colStringAttr=&quot;One&quot;> One</colString> 1</colInt> <MyTable2> One</colString> 1</colInt> </MyTable2> </MyTable1> </MyDataSet>

</li> <li>Save the document as Data.xml in the root folder of your hard disk.</li> <li> In Visual Studio .NET, create a new Microsoft Visual C# .NET Console Application project. Replace the code in Class1.cs with the following code: using System; using System.Data; using System.Xml; using System.Xml.XPath;

namespace Q318148 {   class Class1 {       public static void Main {

XmlDataDocument xd = new XmlDataDocument; xd.DataSet.ReadXml( &quot;c:\\data.xml&quot;); xd.DataSet.AcceptChanges;

Console.WriteLine( xd.DocumentElement.FirstChild.FirstChild.InnerXml ); //Comment the following line. xd.DocumentElement.FirstChild.FirstChild.InnerXml = &quot;AA&quot;; //Uncomment the following 2 lines to get the correct behavior. //System.Xml.XmlNode node = xd.DocumentElement.FirstChild.FirstChild; //node.InnerText =&quot;AA&quot;;

Console.WriteLine( xd.DocumentElement.FirstChild.FirstChild.InnerXml ); Console.WriteLine(&quot;&quot;); Console.WriteLine( xd.DataSet.GetXml);

}   } }

</li></ol>

The following output is generated. The original value of colString is shown on the first line, followed by the replaced value. Notice that the value of colString under the MyTable1 element does not contain any values in the XML that is generated below it. Zero AA

<MyDataSet> <MyTable1 colStringAttr=&quot;Zero&quot;>  0</colInt> <MyTable2> Zero</colString> 0</colInt> </MyTable2> </MyTable1> <MyTable1 colStringAttr=&quot;One&quot;> One</colString> 1</colInt> <MyTable2> One</colString> 1</colInt> </MyTable2> </MyTable1> </MyDataSet>

To resolve the problem: <ol> <li> Comment the following line of code: xd.DocumentElement.FirstChild.FirstChild.InnerXml = &quot;AA&quot;; </li> <li> Uncomment the following lines of code: System.Xml.XmlNode node = xd.DocumentElement.FirstChild.FirstChild; node.InnerText =&quot;AA&quot;; The following output is generated. The modified node text is also reflected in the DataSet. Zero AA

<MyDataSet> <MyTable1 colStringAttr=&quot;Zero&quot;> AA</colString> 0</colInt> <MyTable2> Zero</colString> <colInt>0</colInt> </MyTable2> </MyTable1> <MyTable1 colStringAttr=&quot;One&quot;> <colString>One</colString> <colInt>1</colInt> <MyTable2> <colString>One</colString> <colInt>1</colInt> </MyTable2> </MyTable1> </MyDataSet> </li></ol>

Keywords: kbbug kbpending kbvs2002sp1sweep KB318148

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.