title: Linq to XML Read xml file using linq
body: <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE Report SYSTEM "https://abc.mycompany.com/abc/processingreports/processeddtd/abcd_1_8.dtd"&gt;
  &lt;Report Name="Daily TRANSACTIONS"
          Version="1.8"
          xmlns="https://abc.mycompany.com/abc/processingreports/processeddtd/abcd_1_8.dtd"
          OrgID="ABC_PQR" StartDate="2011-03-10T00:00:00+00:00" EndDate="2011-03-11T00:00:00+00:00"&gt;
      &lt;Requests&gt;
          &lt;Request ID="2"
                   Date="2011-03-10T00:21:14+00:00"
                   OrderNumber="1"&gt;
              &lt;BillTo&gt;
                  &lt;FirstName /&gt;
              &lt;/BillTo&gt;
              &lt;LineItems&gt;
                  &lt;LineItem Number="0"&gt;
                      &lt;Quantity /&gt;
                  &lt;/LineItem&gt;
              &lt;/LineItems&gt;
          &lt;/Request&gt;
          &lt;Request ID="2"
                   Date="2011-03-10T00:21:14+00:00"
                   OrderNumber="1"&gt;
                   TransactionNumber="389958330911111"&gt;
              &lt;BillTo&gt;
                  &lt;FirstName&gt;A&lt;/FirstName&gt;
              &lt;/BillTo&gt;
              &lt;LineItems&gt;
                  &lt;LineItem Number="0"&gt;
                      &lt;Quantity&gt;1&lt;/Quantity&gt;
                  &lt;/LineItem&gt;
              &lt;/LineItems&gt;
              &lt;UniqueData&gt;
                  &lt;UniqueNumber&gt;11111111111111111111111111111&lt;/UniqueNumber&gt;
              &lt;/UniqueData&gt;&lt;/Request&gt;&lt;/Requests&gt;&lt;/Report&gt;
  </code></pre>
  
  <blockquote>
    <p>In above XML file using Linq i just
    want to extract OrderNumber and
    UniqueNumber 
                       OrderNumber="1"
                      11111111111111111111111111111
       </p>
  </blockquote>
  
  <p>Any ideas, suggestions to extract these details?</p>
  
  <p>I can select elements from above xml file but UniqueNumber is not associated with OrderNumber</p>
  
  <p>I am looking for something below (ignore lines where UniqueNumber is not present)
  OrderNumber - assosicated UniqueNumber</p>
  
  <p>Update
  <strong>In "requiredElements" i am expecting two coulmns OrderNumber and UniqueNumber and holding associated values with each other as 1 and 11111 and so one</strong></p>
  
  <pre><code> #region FileOpen with UTF8 Encoding
  
   TextReader sr = new StreamReader(cFileName, Encoding.UTF8);
   XDocument reportfile = XDocument.Load(sr, LoadOptions.SetBaseUri);
   XElement xd = XElement.Parse(reportfile.ToString());
   sr.Close();
  
  
   #endregion
  
   XNamespace ns = xd.Attribute("xmlns").Value;
  
   var requiredElements = (from resultquery in reportfile.Descendants()
                            select new
                            {
                               OrderNumber = resultquery.Attribute("OrderNumber"),
                               UniqueNumber= (string)resultquery.Element(AddNameSpace(ns, "UniqueNumber")),
                            }
                        );
  </code></pre>