LINQ to XML via C#

Posted by user70192 on Stack Overflow See other posts from Stack Overflow or by user70192
Published on 2010-12-27T12:31:11Z Indexed on 2010/12/27 12:54 UTC
Read the original article Hit count: 464

Filed under:
|
|
|

Hello,

I'm new to LINQ. I understand it's purpose. But I can't quite figure it out. I have an XML set that looks like the following:

<Results>
  <Result>
    <ID>1</ID>
    <Name>John Smith</Name>
    <EmailAddress>[email protected]</EmailAddress>
  </Result>
  <Result>
    <ID>2</ID>
    <Name>Bill Young</Name>
    <EmailAddress>[email protected]</EmailAddress>
  </Result>
</Results>

I have loaded this XML into an XDocument as such:

string xmlText = GetXML();
XDocument xml = XDocument.Parse(xmlText);

Now, I'm trying to get the results into POCO format. In an effort to do this, I'm currently using:

var objects = from results in xml.Descendants("Results")
              select new Results
              // I'm stuck

How do I get a collection of Result elements via LINQ? I'm particularly confused about navigating the XML structure at this point in my code.

Thank you!

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml