C# 为什么获取xml数据集表会返回所有值?

C# 为什么获取xml数据集表会返回所有值?,c#,winforms,dataset,C#,Winforms,Dataset,目前,我有一个Datagridview显示一些XML数据,数据是 <?xml version="1.0" encoding="utf-8" ?> <survey> <floor location="Drill Floor"> <sign location ="1" ref="OFS-FE01" size="180x180" Material="RPP" Quantity="2" Backingboard="No" /> <

目前,我有一个Datagridview显示一些XML数据,数据是

<?xml version="1.0" encoding="utf-8" ?> 
<survey>
  <floor location="Drill Floor">
    <sign location ="1" ref="OFS-FE01" size="180x180"  Material="RPP" Quantity="2" Backingboard="No"  />
  </floor>
  <floor location="Top Deck">
    <sign location ="2" ref="OFS-FE07" size="180x180"  Material="RPP" Quantity="2" Backingboard="Yes"  />
  </floor>
  </survey>

上面是我加载datagridview的方式,它可以工作,但它可以获得所有位置,而我只想从某个楼层获得它

您可以预处理XML文件以删除不希望在数据网格视图中显示的数据,我假设basicStorage.sws是一个XML文件

例如:

private void Form4_Load(object sender, EventArgs e)
{
    XDocument storedData = XDocument.Load(@"basicStorage.sws");

    // the floor that you want to keep
    string selectedFloor = "Drill Floor";

    // remove everything that isn't the floor we want to keep
    storedData
        .Descendants("floor")
        .Where(a => a.Attribute("location").Value != selectedFloor)
        .Remove();

    // now use the remaining xml to populate the dataset
    DataSet dataSet = new DataSet();
    dataSet.ReadXml(storedData.CreateReader());
    datagridview.DataSource = dataSet.Tables[1].DataSet.Tables[1];
}

谢谢你,这封信离开办公室几天了,所以我才刚刚看到。
private void Form4_Load(object sender, EventArgs e)
{
    XDocument storedData = XDocument.Load(@"basicStorage.sws");

    // the floor that you want to keep
    string selectedFloor = "Drill Floor";

    // remove everything that isn't the floor we want to keep
    storedData
        .Descendants("floor")
        .Where(a => a.Attribute("location").Value != selectedFloor)
        .Remove();

    // now use the remaining xml to populate the dataset
    DataSet dataSet = new DataSet();
    dataSet.ReadXml(storedData.CreateReader());
    datagridview.DataSource = dataSet.Tables[1].DataSet.Tables[1];
}