title: Using XPATH to access XML elements (was: Good tutorial to learn xpath)
body: <p>I am trying to learn XPath. The theory seems extremely simple, except for the fact that it doesn't work.</p>
  
  <p>I am trying to get the content of every target element</p>
  
  <pre><code>XPathDocument doc = new XPathDocument(sPath);
  XPathNavigator nav = doc.CreateNavigator();
  XPathExpression expr;
  expr = nav.Compile("/doc/file/body/trans-unit/target");
  XPathNodeIterator iterator = nav.Select(expr);
  
  while (iterator.MoveNext())
  {
      XPathNavigator nav2 = iterator.Current.Clone();
      sbDoc.Append(nav2.InnerXml);
  }
  </code></pre>
  
  <p>The XML doc looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;doc version="1.2"&gt;
    &lt;file original="affiliate.php" source-language="EN-US" target-language="FR-FR" datatype="php"&gt;
      &lt;header&gt;
        &lt;skl&gt;
          &lt;external-file href="affiliate.php"/&gt;
        &lt;/skl&gt;
      &lt;/header&gt;
      &lt;body&gt;
        &lt;trans-unit id="tu1"&gt;
          &lt;source xml:lang="EN-US"&gt;Your Program Details&lt;/source&gt;
          &lt;target xml:lang="FR-FR"&gt;Your Program Details&lt;/target&gt;
        &lt;/trans-unit&gt;
        &lt;trans-unit id="tu2"&gt;
          &lt;source xml:lang="EN-US"&gt;Status&lt;/source&gt;
          &lt;target xml:lang="FR-FR"&gt;Status&lt;/target&gt;
        &lt;/trans-unit&gt;
  </code></pre>
  
  <p>This is nearly word for word from a tutorial, but I can't get it to work. When the iterator is created, in debug mode, I can see that the document is loaded, but iterator finds no result and skips the While loop.</p>
  
  <p>I am probably doing something extremely stupid, but what?</p>
  
  <p>Anyone knows where I can find a good, reliable XPATH tutorial?</p>
  
  <hr>
  
  <p>Thanks all. Turns out I ignored the fact that there was a namespace (which I removed while simplifying the XML code as I didn't realize it was important), and with the addition of a namespace manager, the code works fine. </p>
  
  <p>I am now studying the XPATH tutorials proposed and they look good.</p>