none
An inconsistency between DataSet.GetXml() and DataSet.ReadXml() RRS feed

  • Question

  • I use the DataSet.GetXml() method to retrieve the XML representation of the DataSet object as a string object. The GetXml() method tacks on a root element called NewDataSet to the XML before returning it. Now I write that out to a file using System.IO.StreamWriter and then call DataSet.ReadXml(string path, XmlReadMode xrm) to recreate the DataSet. No matter what XmlReadMode I specify to the ReadXml method, the DataSet that's recreated is one DataTable short of the DataSet I called GetXml() on - or in other words, the NewDataSet element is missing.

     

    Could someone please explain this? And how can I get around this?

     

    Thanks.

     

    Tuesday, January 22, 2008 9:03 PM

All replies

  • There's nothing to get around.  There's no missing DataTable.

     

    The NewDataSet element is a top-level element that encloses all of the other elements.  It doesn't correspond to a DataTable; it corresponds to the DataSet.  The element's name is the value of the DataSet's Name property - which, unless you've changed it, is NewDataSet.

     

    (Just to be stupidly pedantic: it's "top-level element," not "root element," because the root of an XML document isn't an element, but rather an abstraction, whose children can include any number of processing instructions, comments, and the top-level element.  There are times - this isn't really one of them, but I'm a little obsessive-compulsive - when this distinction is actually important.)

     

    Friday, January 25, 2008 12:13 AM