title: What is the correct use of XmlNode.SelectSingleNode(string xpath) in C#?
body: <p>I'm having trouble dealing with some XML file (which is at the end of this post).</p>
  
  <p>I wrote the following code in order to get <code>Job_Id</code> data related to a given <code>Job_Name</code> pattern whose owner <code>Job_Owner</code> is the user running the probram:</p>
  
  <pre><code>List&lt;String&gt; jobID = new List&lt;String&gt;();
  XmlNodeList nodes = xml.SelectNodes("//Job");
  foreach (XmlNode node in nodes)
  {
      innerNode = node.SelectSingleNode("//Job_Owner"); // SelectSingleNode here always selects the same node, but I thought it should be relative to node, not to nodes
      if (!innerNode.InnerText.Contains(Environment.UserName))
      {
          continue;
      }
      innerNode = node.SelectSingleNode("//Job_Name");
      if (!Regex.IsMatch(innerNode.InnerText, jobNamePattern, RegexOptions.Compiled))
      {
          continue;
      }
      innerNode = node.SelectSingleNode("//Job_Id");
      jobID.Add(innerNode.InnerText);
  }
  </code></pre>
  
  <p>I would expect that <code>node.SelectSingleNode("//Job_Name")</code> seeks for a tag named <code>Job_Name</code> only under the xml code represented by <code>node</code>.</p>
  
  <p>That is not what it seems to be happening, as it always return the same node, doesn't matter at what step of the <code>foreach</code> it is (i.e. the <code>node</code> selected from the <code>nodes</code> changes, but the <code>node.SelectSingleNode("//Job_Name")</code> always return the same content).</p>
  
  <p>What is wrong with this code?</p>
  
  <p>Thanks in advance!</p>
  
  <p>--</p>
  
  <p>The XML File looks like this:</p>
  
  <pre><code>&lt;Data&gt;
      &lt;Job&gt;
          &lt;Job_Id&gt;58282.minerva&lt;/Job_Id&gt;
          &lt;Job_Name&gt;sb_net4_L20_sType1&lt;/Job_Name&gt;
          &lt;Job_Owner&gt;mgirardis@minerva&lt;/Job_Owner&gt;
          &lt;!--more tags--&gt;
      &lt;/Job&gt;
      &lt;Job&gt;
          &lt;!--etc etc etc--&gt;
      &lt;/Job&gt;
      &lt;!--etc etc etc--&gt;
  &lt;/Data&gt;
  </code></pre>