Question: I have a C# .NET app that contains a dynamically generated xml document. It tracks order info, such as name, date the order was placed, all that sort of stuff. I have no issue extracting the information contained in these tags using innerText.

However, when the order is 'built' by our customer, they are allowed to attach files....

Each file is saved in the xml doc under the tag 

So I end up with something (simplified) like this:

```
<order>
   <Number>1</Number>
   <Email>example@stack.com</Email>
   <Date>2012-08-13</Date>
   <File>File1.txt</File>
   <File>File2.txt</File>
</order>

```

As I said, I extract the other info using

```
   foreach (XmlElement element in file.SelectNodes("/order"))
   {
       String strNumber = element.SelectSingleNode("Number").InnerText,
               strEmail = element.SelectSingleNode("Email").InnerText,
                strDate = element.SelectSingleNode("Date").InnerText;
   } 

```

However when I do this with name, I get an error honking about not being set to an instance... Which I totally understand.

My question is, how can I get this info? There can be any number of Files attached, from zero to however many the user wants.

Thank you for your time.

Answer: 
Here is code example.

Order represent xml order

```
[TestFixture]
public class ForTest
{
    [Test]
    public void Test()
    {
        var root = XElement.Load("order.xml");
        var order = CreateOrder(root);
    }

    private Order CreateOrder(XElement element)
    {
        var result = new Order
        {
            Number = int.Parse(element.Element("Number").Value),
             Date = DateTime.Parse(element.Element("Date").Value),
            Email = element.Element("Email").Value,
            Files = element.Descendants("File").Select(x => x.Value).ToList()
        };
        return result;
    }
}
public class Order
{
    public int Number { get; set; }
    public string Email { get; set; }
    public DateTime Date { get; set; }
    public List<string> Files { get; set; }
}

```
Here's a LINQ based solution:

```
XDocument XMLDoc = XDocument.Load("XMLFile.xml");
var LoadInfo =  from Node in XMLDoc.Descendants("order")                       
                select new
                  {
                    Number = Node.Element("Number").Value,
                    Email = Node.Element("Email").Value,
                    Date = Node.Element("Date").Value,
                    File = Node.Element("File").Value,
                  };

```

Usage:

```
    foreach(var Info in LoadInfo)
    {
      //Do something with the info.
      //Console.WriteLine(Info.Email);
    }

```