0

I have to read a dynamically created xml documnet to a dataset.But don't know how to achieve that.I wrote some code as below.

    private void ConvertXMLToDT(string myXML)
    {
        XmlDocument xmlDocs = new XmlDocument();
        xmlDocs.LoadXml(myXML);
        DataSet ds = new DataSet();
        ds.ReadXml(xmlDocs);   //--->this statement doesn't work
        DataTable dtFormats = ds.Tables[0];
        DataTable dtPreset1 = ds.Tables[1];        
        Response.Write("done");
    }

Is there any possible way to do that.

Arvin
  • 954
  • 3
  • 14
  • 33

2 Answers2

1

I have modified my code as per the comments above in the questions and working fine now

private void ConvertXMLToDT(string myXML)
{
    //XmlDocument xmlDocs = new XmlDocument();
    //xmlDocs.LoadXml(myXML);
    DataSet ds = new DataSet();
    //ds.ReadXml(xmlDocs);   //--->this statement doesn't work
    ds.ReadXml(XmlReader.Create(new StringReader(myXML)));
    DataTable dtFormats = ds.Tables[0];
    DataTable dtPreset1 = ds.Tables[1];        
    Response.Write("done");
}
Arvin
  • 954
  • 3
  • 14
  • 33
1

It may help for you:

 public DataTable ConvertXMLToDT(string xml)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(new XmlTextReader(new StringReader(xml)));
        return ds.Tables[0];
    }
Peter
  • 27,590
  • 8
  • 64
  • 84
Kumar Manish
  • 3,746
  • 3
  • 37
  • 42