i need to pull data out of an xml file based on certain field values. the xml file is set up like this
<main>
<report>
<version>1.0</version>
<ID>1234</ID>
<field>
<acel>80</acel>
<decel>50</decel>
<left>20</left>
<right>10</right>
<category>1-10</category>
</field>
<field>
<acel>30</acel>
<decel>54</decel>
<left>12</left>
<right>13</right>
<category>10-20</category>
</field>
<field>
<acel>34</acel>
<decel>210</decel>
<left>27</left>
<right>9</right>
<category>20-30</category>
</field>
</report>
<report>
....
</report>
</main>
I currently have the following:
var query = doc.Descendants("report")
.Select(raw => new
{
version = (string)raw.Element("version"),
tcid = (string)raw.Element("id"),
forces = raw.Element("field").Elements("acel").Select(acel => (int)acel).ToList()
});
I need to search the file for reports that match specific ID’s and specific versions, and then get the accsociated fields acel, decel, left, right etc.
ex I need to find a report for ID 1234 and version 1.0, and have all the field values 80, 50 etc. Any help is great. I have code that returns ID and version already but I’m having trouble getting all the values of field based on version and ID.
Thanks.
To give you a hint:
We first fetch
reportnodes and filter those to the ones matchingIDof1234– that leaves us with first one from your example. Next, we query all thefieldnodes within this report, and extract new objects basing on field values. Lookssimpleawesome? It really is!