DataSet读取Xml问题
假如我有一xml文件结构如下
<root>
<row>
<key> A </key>
<value> 1 </value>
</row>
<row>
<key> B </key>
<value> 2 </value>
</row>
<row>
<key> A </key>
<value> 3 </value>
</row>
</root>
现在我要用dataset把row下面节点key为A的记录都读到datagrid或gridview里面去
应怎样写才好?请路高手帮帮忙!!!
------解决方案--------------------DataSet ds = new DataSet();
ds.ReadXML();
------解决方案--------------------DataSet ds = new DataSet();
DataSet myDataSet = new DataSet();
FileStream fin ;
fin = new FileStream(Server.MapPath( "xmlfile.xml "),FileMode.Open,FileAccess.Read,FileShare.ReadWrite) ;
ds.ReadXml(fin);
fin.Close();
DataTable customerTable = ds.Tables[0];
DataView dv=new DataView(customerTable, "key= 'A ' ", "key ",DataViewRowState.CurrentRows);
......
------解决方案--------------------DataSet dset = new DataSet();
dset.ReadXml( "D:\\my.xml ");
DataTable dt = dset.Tables[0];
DataView dv = new DataView(dt, "key= 'A ' ", "key ", DataViewRowState.CurrentRows);
GridViewList.DataSource = dv;
------解决方案--------------------DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath( "XMLFile.xml "));
DataTable dtRtn = new DataTable();
dtRtn.Columns.Add( "key ");
dtRtn.Columns.Add( "value ");
DataRow drNew = null;
int intRow = ds.Tables[ "row "].Rows.Count;
for (int i = 0; i < intRow; i++)
{
drNew = dtRtn.NewRow();
if (ds.Tables[ "row "].Rows[i][ "key "].ToString().Equals( "A "))
{
drNew[ "key "] = ds.Tables[ "row "].Rows[i][ "key "];
drNew[ "value "] = ds.Tables[ "row "].Rows[i][ "value "];
dtRtn.Rows.Add(drNew);
}
}
this.grvRtn.DataSource = dtRtn;
this.grvRtn.DataBind();
------解决方案--------------------DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath( "s.xml "));
DataGrid dg = new DataGrid();
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "Key= 'A ' ";
dg.DataSource = dv;
dg.DataBind();
this.panel1.Controls.Add(dg);
------解决方案--------------------如果你的XML是一个字符串,且想操作DataSet中的表,如下:
string xml;
DataSet ds = new DataSet();
StringReader sr = new StringReader(xml);
ds.ReadXml(sr);
DataTable dt = ds.Tables[0];
DataRow[] foundRow;
foundRow = dt.Select( "key= 'A ' ", " ");
foreach (DataRow dr in foundRow)