title: Understanding parsing of XML elements
body: <p>I have the following XML in a file.</p>
  
  <pre><code>        &lt;config&gt;
          &lt;appSettings&gt;
                  &lt;DEV&gt;
                  &lt;INDIR&gt;\\serv1\TEST\INDIR\&lt;/INDIR&gt;
                  &lt;OUTDIR&gt;\\serv1\TEST\OUTDIR\&lt;/OUTDIR&gt;
                  &lt;LOGDIR&gt;\\serv1\TEST\LOGDIR\&lt;/LOGDIR&gt;
                  &lt;/DEV&gt;
                  &lt;STAGE&gt;
                  &lt;INDIR&gt;\\serv1\INDIR\&lt;/INDIR&gt;
                  &lt;OUTDIR&gt;\\serv1\OUTDIR\&lt;/OUTDIR&gt;
                  &lt;LOGDIR&gt;\\serv1\LOGDIR\&lt;/LOGDIR&gt;
                  &lt;/STAGE&gt;
                  &lt;PROD&gt;
                  &lt;INDIR&gt;\\serv2\INDIR\&lt;/INDIR&gt;
                  &lt;OUTDIR&gt;\\serv2\OUTDIR\&lt;/OUTDIR&gt;
                  &lt;LOGDIR&gt;\\serv2\LOGDIR\&lt;/LOGDIR&gt;
                  &lt;/PROD&gt;
          &lt;/appSettings&gt; 
          &lt;execSettings&gt;
                  &lt;DEV&gt;
                  &lt;FILTER&gt;*.TXT&lt;/FILTER&gt;
                  &lt;RETENTION&gt;7&lt;/RETENTION&gt; &lt;!-- in days --&gt;
                  &lt;/DEV&gt;
                  &lt;STAGE&gt;
                  &lt;FILTER&gt;*.TXT&lt;/FILTER&gt;
                  &lt;RETENTION&gt;14&lt;/RETENTION&gt; &lt;!-- in days --&gt;
                  &lt;/STAGE&gt;
                  &lt;PROD&gt;
                  &lt;FILTER&gt;*.TXT&lt;/FILTER&gt;
                  &lt;RETENTION&gt;60&lt;/RETENTION&gt; &lt;!-- in days --&gt;
                  &lt;/PROD&gt;    
          &lt;/execSettings&gt; 
      &lt;/config&gt;
  </code></pre>
  
  <p>Using a variable named ‘platform’ holding the string “DEV” or “STAGE” or “PROD”, I want<br>
  to get the elements of that platform from the respective part in appSettings and  execSettings<br>
  and set them in the following class.</p>
  
  <pre><code>        public class config
      {
              public string InDir { get; set; }
              public string OutDir { get; set; }
              public string LogDir { get; set; }
              public string Filter { get; set; }
              public Int32 Retention { get; set; }
      }
  </code></pre>
  
  <p>Here is the code attempt. As indicated in comments, my counts are zero for the node<br>
  lists. Any help on this is appreciated.</p>
  
  <pre><code>        XmlDocument xDoc = new XmlDocument();
      string platform = "DEV";
      IEnumerator ienum;
      try
      { 
      xDoc.Load(xmlFile);
      string xPath1 = "appSettings/" + platform;
      string xPath2 = "execSettings/" + platform;
  
      XmlNodeList appElements = xDoc.GetElementsByTagName("xPath1");  //count = 0
      XmlNodeList execElements = xDoc.GetElementsByTagName("xPath2"); //count = 0
  
      config cSet = new config();
  
      ienum = appElements.GetEnumerator(); //null
      while (ienum.MoveNext())
      {
              XmlNode INDIR = (XmlNode)ienum.Current;
              XmlNode OUTDIR = (XmlNode)ienum.Current;
              XmlNode LOGDIR = (XmlNode)ienum.Current;
              cSet.InDir = INDIR.InnerText;
              cSet.OutDir = OUTDIR.InnerText;
              cSet.LogDir = LOGDIR.InnerText;
      }
  
      ienum = execElements.GetEnumerator(); //null
      while (ienum.MoveNext())
      {
              XmlNode FILTER = (XmlNode)ienum.Current;
              XmlNode RETENTION = (XmlNode)ienum.Current;
              cSet.Filter = FILTER.InnerText;
              cSet.Retention = RETENTION.InnerText;
      }  
  </code></pre>
  
  <p>With the feedback I've received (thanks to all), here is an updated code posting, condensed, but I'm still seeing count = 0 for the XmlNodeList. </p>
  
  <pre><code>        XmlDocument xDoc = new XmlDocument();
          string platform = "DEV";
          try
          { 
                  xDoc.Load(xmlFile);
                  string xPath1 = "appSettings/" + platform;
                  XmlNodeList appElements = xDoc.SelectNodes("xPath1");  //count = 0
  
                  config cSet = new config();
                  foreach (XmlNode node in appElements)
                  {
                          cSet.InDir = node["./INDIR"].InnerText;
                  }
          }
          catch (Exception ex)
          {
                  ADHOC.func.RecordTo_LogFile("XML||Load_Failure");
                  throw (ex);
          }
  </code></pre>