To convert String XML into a data table in C#
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unboun开发者_如何学Pythonded">
<xs:element name="Table">
<xs:complexType>
<xs:attribute name="DataColumn" type="xs:string" />
<xs:attribute name="ddlSchema" type="xs:string" />
<xs:attribute name="ddlTable" type="xs:string" />
<xs:attribute name="ddlColumn" type="xs:string" />
<xs:attribute name="DefaultValue" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Table DataColumn="ID" ddlSchema="" ddlTable="" ddlColumn="" DefaultValue="" />
<Table DataColumn="CategoryName" ddlSchema="" ddlTable="" ddlColumn="" DefaultValue="" />
<Table DataColumn="ParentCatID" ddlSchema="" ddlTable="" ddlColumn="" DefaultValue="" />
<Table />
</NewDataSet>
is my Xml which is save in data base column so how it will convert into Data set so i can bind the Grid ? any suggestion
Use the DataSet.ReadXml method for this purpose.
DataSet ds;
StringReader reader = new StringReader(string);
ds.ReadXml(reader);
dataGridView1.DataSource = ds.Tables["TableName"];
I'd recommend you to use linq, then you can do something like this
Updated: adapted to your xml, Update 2: fixed the namespace to match your xml
var xmlSource = XElement.Parse(xmlString);
XNamespace xs = "http://www.w3.org/2001/XMLSchema";
var xQuery = (from c in xmlSource.Descendants(xs + "NewDataSet")
select c);
gridview1.DataSource = xQuery;
gridview1.DataBind();
By using the Following CodePart you can convert the XML file data into a DataSet
DataSet dsStore = new DataSet();
dsStore.ReadXml(<Path> + "\\DataBaseValues.xml");
return dsStore.Tables["MyData"];
精彩评论