Posts Tagged ‘XML’

h1

Convert XML to Datatable

July 19, 2010

DataSet ds= new DataSet();
DataTable dtComp = new DataTable();
System.IO.StringReader rdr;
string sXML =  xmldoc.ToString();
rdr = new System.IO.StringReader(sXML);
ds.ReadXml(rdr);
if ( ds.Tables.Count > 0)
{
dtComp = ds.Tables[0];
}

Convert XML to Datatable with XML Schema : Function

private DataSet getDataSet(string sXML, string xSchema)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
System.IO.StringReader rdr;
rdr = new System.IO.StringReader(sXML);
System.IO.StringReader rdrSchema;
rdrSchema = new System.IO.StringReader(xSchema);
ds.ReadXmlSchema(rdrSchema);
ds.ReadXml(rdr);
if (ds.Tables.Count > 0)
{
return ds;
}
return ds;
}