Skip to content

Instantly share code, notes, and snippets.

@CodingGorilla
Created January 10, 2011 21:02
Show Gist options
  • Save CodingGorilla/773467 to your computer and use it in GitHub Desktop.
Save CodingGorilla/773467 to your computer and use it in GitHub Desktop.
Quick LINQ to XML sample for Lambo
XDocument doc = XDocument.Load("my-xml-file.xml");
foreach(XElement el in doc.Descendants("row")
{
test.actual = el.Descendants("var").Where( x => (string)x.Attribute("name") == "account" ).Single().Attribute("value").Value;
test.actual = el.Descendants("var").Where( x => (string)x.Attribute("name") == "commitment").Single().Attribute("value").Value;
/* Repeat the above as need for additional 'var' element values */
}
<row>
<var name="budgetYear" value="2008" />
<var name="account" value="0010" />
<var name="actual" value="8241" />
<var name="commitment" value="537" />
<var name="costCentre" value="E2000" />
<var name="internalCostCentre" value="101" />
</row>
<row>
<var name="budgetYear" value="2008" />
<var name="account" value="dodgy" />
<var name="actual" value="8241" />
<var name="commitment" value="537" />
<var name="costCentre" value="E2000" />
<var name="internalCostCentre" value="101" />
<row>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment