0

I'm trying to load a list from xml. each node has few nodes. I know it's possible to do it in a foreach loop like in the picture below, but i would like to avoid using a loop.

this is what I don't want, but without the loop: enter image description here

I saw this examle, but it's only for one node "id". How can I transform XML into a List<string> or String[]?

Thanks.

Community
  • 1
  • 1
Itay.B
  • 3,991
  • 14
  • 61
  • 96

1 Answers1

3
var contacts = from c in xdoc.Descendants("contact")
               select new Contact()
               {
                  GUID = (string)c.Element("Guid"),
                  Name = (string)c.Element("Name"),
                  Email = (string)c.Element("Email"),
                  PhoneNumber = (string)c.Element("PhoneNumber")
               };

Where xdoc is an instance of XDocument class.

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459