title: Obtain XML child nodes using C#
body: <p>This is my first time attempting to parse XML using C# and feel like I'm running in circles right now. I am calling a WCF web service which, based upon user input, conducts a search through a database against company names. It returns the results in an XML document with each entry formatted as it is below. </p>
  
  <p>Given this XML structure, how would I go about obtaining the values for the  <code>d:AccountId</code> and <code>d:Name</code> nodes using <code>C#</code>? </p>
  
  <pre><code>&lt;entry&gt;
      &lt;id&gt;&lt;/id&gt;
      &lt;title type=\"text\"&gt;&lt;/title&gt;
      &lt;updated&gt;&lt;/updated&gt;
      &lt;author&gt;&lt;name /&gt;&lt;/author&gt;
      &lt;link rel=\"edit\" title=\"Account\" href=\"AccountSet\" /&gt;
      &lt;category term=\"Microsoft.Crm.Sdk.Data.Services.Account\" scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\" /&gt;
      &lt;content type=\"application/xml\"&gt;
      &lt;m:properties&gt;
          &lt;d:neu_UniqueId&gt;&lt;/d:neu_UniqueId&gt;
          &lt;d:AccountId m:type=\"Edm.Guid\"&gt;&lt;/d:AccountId&gt;
          &lt;d:Name&gt;&lt;/d:Name&gt;
      &lt;/m:properties&gt;&lt;/content&gt;
  &lt;/entry&gt;
  </code></pre>
  
  <p>Here is my first attempt. The program threw an exception at the <code>node3</code> variable. </p>
  
  <pre><code>        try
          {
              WebRequest myWebRequest = WebRequest.Create(URL);
              myWebRequest.PreAuthenticate = true;
              myWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
  
              //myWebRequest.Headers.Add("Access-Control-Allow-Origin", url);
  
              WebResponse myWebResponse = myWebRequest.GetResponse();
              Stream myFileStreamResult = myWebResponse.GetResponseStream();
              Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
              StreamReader readStream = new StreamReader(myFileStreamResult, encoder);
  
              results = readStream.ReadToEnd();
  
              XmlDocument xmlDoc = new XmlDocument();
              xmlDoc.LoadXml(results);
              XmlNodeList parentNode = xmlDoc.GetElementsByTagName("entry");
  
              foreach (XmlNode childNode in parentNode)
              {
  
                  string node = childNode.ToString();
                  string node2 = childNode.Value;
                  string node3 = childNode.Attributes["title"].Value;
                  string node7 = childNode.Attributes["m:properties"].Value;
                  string node8 = childNode.Attributes["m:properties\\d:AccountId"].Value;
                  string node9 = childNode.Attributes["m:properties\\d:Name"].Value;
                  string node10 = childNode.Attributes["m:properties\\d:AccountId"].Value;
              }
  
          }
  </code></pre>