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: 
You can do this using serialization if you know the properties

```
[XmlRoot("order")]
public class order
{
[XmlElement("Number")]
public string  Number{get;set;}
[XmlElement("Email")]
public string  Email{get;set;}
[XmlElement("Date")]
public string  Date{get;set;}
[XmlElement("File")]
public string[] File{get;set;}
}

```

The below code is to deserialize

```
    public static T DeSerializeXMLString<T>(string xmlString)
    {
        XmlSerializer xs = new XmlSerializer(typeof(T));
        MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(xmlString));
        XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
        return (T)xs.Deserialize(memoryStream);
    }

```
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);
    }

```