title: Need help retrieving XML data using Linq
body: <p>I am trying to retrieve data from an XML file and return the parsed data in a list. Depending on what I use to access the data (Element or Attributes) I either get null (in case of Element) or something I cannot decipher (in case of Attributes).</p>
  
  <p>XML Looks like this:</p>
  
  <pre><code>&lt;DATA_RESPONSE&gt;
      &lt;HEADER&gt;
          &lt;MSGID&gt;IS20101P:091317125610:98::34:0&lt;/MSGID&gt;
      &lt;/HEADER&gt;
      &lt;DATA&gt;
          &lt;ROW ID='IS20101P' PE_NAME='APP-029' PE_ID='4' CODE='4829' DATA='5,1,500,1'  /&gt;
          &lt;ROW ID='IS20101P' PE_NAME='APPS-029' PE_ID='4' CODE='4829' DATA='4,1,500,1' /&gt;
          ...
      &lt;/DATA&gt;
      &lt;SUMMARY&gt;
      &lt;/SUMMARY&gt;
      &lt;ERRORS&gt;
      &lt;/ERRORS&gt;
  &lt;/DATA_RESPONSE&gt;
  </code></pre>
  
  <p>I am using the following to get the data. I read the file and store XML in a string and call a method with this string as argument:</p>
  
  <pre><code>public static Hashtable GetIDSData(string sXMLString)
  {
      Hashtable result = new Hashtable();
  
      result.Add("Success", false);
      result.Add("ErrorMessage", "");
      result.Add("ID", "");
      result.Add("PE_NAME", "");
      result.Add("PE_ID", "");
      result.Add("CODE", "");
      result.Add("DATA", "");
  
      xmlDoc.InnerXml = sXMLString;
      XmlElement root = xmlDoc.DocumentElement;
      XDocument doc = XDocument.Parse(sXMLString);
      XmlNode node = xmlDoc.SelectSingleNode("DATA_RESPONSE/DATA"); 
  
      if (node != null)
      {
          var AddressInfoList = doc.Root.Descendants("ROW").Select(Address =&gt; new
          {
              ID = Address.Attributes("ID")?.ToString(),
              PEName = Address.Attributes("PE_NAME")?.ToString(),
              PEID = Address.Attributes("PE_ID")?.ToString(),
              Code = Address.Attributes("CODE")?.ToString(),
              Data = Address.Attributes("DATA")?.ToString(),
          }).ToList();
  
          foreach (var AddressInfo in AddressInfoList)
          {
              if (string.IsNullOrEmpty(AddressInfo.Code))
              {
                  result["Success"] = false;
                  result["ErrorMessage"] = "Invalid Code; code is empty.";
              }
              else
              {
                  result["Success"] = true;
                  result["ErrorMessage"] = "";
                  result["ID"] = AddressInfo.ID;
                  result["PE_NAME"] = AddressInfo.PEName;
                  result["PE_ID"] = AddressInfo.PEID;
                  result["CODE"] = AddressInfo.Code;
                  result["DATA"] = AddressInfo.Data;
              }
          }
          return result;
      }
  </code></pre>
  
  <p>In Linq section, if I use Address.Element("ID").Value, I get null returned.
  There is no namespace used in XML.</p>