Created
January 10, 2011 21:02
-
-
Save CodingGorilla/773467 to your computer and use it in GitHub Desktop.
Quick LINQ to XML sample for Lambo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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