Last active
August 29, 2015 13:58
-
-
Save okaram/9947768 to your computer and use it in GitHub Desktop.
Super Quick Linq to XML
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
<contacts> | |
<contact id="1"> | |
<firstName>Orlando</firstName> | |
<lastName>Karam</lastName> | |
</contact> | |
<contact id="2"> | |
<firstName>Lina</firstName> | |
<lastName>Colli</lastName> | |
</contact> | |
</contacts> |
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 loaded = XDocument.Load(@"C:\contacts.xml"); | |
var contacts = from c in loaded.Descendants("contact") | |
select new { | |
id=(int)c.Attribute("id"), | |
name=(string)c.Element("firstName") +" " +(string)c.Element("lastName"), | |
}; | |
foreach (var c in contacts) | |
Console.WriteLine("Contact: id={0}, name = {1}", c.id, c.name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment