BUG: The data set does not contain CDATA sections after you load an XML document (317706)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft XML Classes (included with the .NET Framework 1.0)

This article was previously published under Q317706

SYMPTOMS

The CDATA sections in an XML document are not inserted correctly in the data table when you use the ReadXml method of the DataSet object to read the XML file.

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Notepad, create a new XML document that contains the following XML data:
    <?xml version="1.0" ?>
    <ROOT>
    	<LEVEL1 name="10"> 
    		<LEVEL2 name="ANNES DELIGHT">
    			<![CDATA[BARRYS]]>
    		</LEVEL2> 
    		<LEVEL2 name="ASHBY PLACE">
    			<![CDATA[ANTONY]]> 
    		</LEVEL2> 
    		<LEVEL2 name="BEHIND MAGNOLIA ELEMENTARY"> 
    			<![CDATA[ROPKA]]> 
    		</LEVEL2> 
    	</LEVEL1> 
    	<LEVEL1 name="20"> 
    		<LEVEL2 name="ABBINGTON RESERVE"> 
    			<![CDATA[MCCOMAS]]> 
    		</LEVEL2> 
    		<LEVEL2 name="BEECHWOOD"> 
    			<![CDATA[ABINGIN]]> 
    		</LEVEL2> 
    		<LEVEL2 name="BUSH RIVER"> 
    			<![CDATA[CHELSEA]]> 
    		</LEVEL2> 
    	</LEVEL1> 
    </ROOT> 
  2. Save the document as Test.xml in the root folder of your hard disk.
  3. In Visual Studio .NET, create a new Microsoft Visual C# .NET Windows Application project.
  4. Drag two Button controls from the toolbox to Form1.
  5. Create a public member in public class Form1 to create a new data set:
    public DataSet ds = new DataSet();
  6. Paste the following code in the Click event procedure of Button1:
    	try
    	{
                    ds.ReadXml("c:\\test.xml");
    	        MessageBox.Show("Done!");
    	}
    	catch (Exception exc)
    	{
    		MessageBox.Show(exc.Message);
    	}
    						
  7. Paste the following code in the Click event procedure of Button2:
    	try
    	{
    		ds.WriteXml("c:\\test_new.xml");
                    MessageBox.Show("New File Written!");
    	}
    	catch (Exception exc)
    	{
    		MessageBox.Show(exc.Message);
    	}
    
    						
  8. Save the changes to the Visual C# .NET project, and then run the application.
  9. Click Button1 to fill the data set with the data from the XML file that you created.
  10. Click Button2 to write out a new XML file (Test_new.xml) from the data set.
  11. Open the new file (Test_new.xml) and note that the XML data is missing the CDATA sections:
    <?xml version="1.0" standalone="yes"?>
    <ROOT>
      <LEVEL1 name="10">
        <LEVEL2 name="ANNES DELIGHT" />
        <LEVEL2 name="ASHBY PLACE" />
        <LEVEL2 name="BEHIND MAGNOLIA ELEMENTARY" />
      </LEVEL1>
      <LEVEL1 name="20">
        <LEVEL2 name="ABBINGTON RESERVE" />
        <LEVEL2 name="BEECHWOOD" />
        <LEVEL2 name="BUSH RIVER" />
      </LEVEL1>
    </ROOT>

Modification Type:MinorLast Reviewed:9/15/2005
Keywords:kbvs2002sp1sweep kbbug kbpending KB317706 kbAudDeveloper