Why does getting a xml dataset table return all values?
Clash Royale CLAN TAG#URR8PPP
Why does getting a xml dataset table return all values?
Currently, I have this Datagridview displaying some XML data, the data is
<?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>
This is where I'm stuck as there are multiple floors and I need a way to display only a chosen floor location.
private void Form4_Load(object sender, EventArgs e)
DataSet dataSet = new DataSet();
dataSet.ReadXml(@"basicStorage.sws", XmlReadMode.Auto);
datagridview.DataSource = dataSet.Tables[1].DataSet.Tables[1];
Above is how im loading the datagridview, It works but it gets all the places, while I only want to get it from a certain floor.
1 Answer
1
You could pre-process the XML file to remove the data which you don't want to show in the data grid view (I'm assuming basicStorage.sws
is an xml file)
basicStorage.sws
For example:
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];
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thank you for this was out of the office for a few days so only just saw this.
– Evan Wrynn
Aug 13 at 8:09