title: XML DOMXPath Searching
body: <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
       &lt;channel&gt;
            &lt;item&gt;
                  &lt;category&gt;Cat1&lt;/category&gt;
            &lt;/item&gt;
            &lt;item&gt;
                  &lt;category&gt;Cat1&lt;/category&gt;
            &lt;/item&gt;
            &lt;item&gt;
                  &lt;category&gt;Cat2&lt;/category&gt;
            &lt;/item&gt;
            &lt;item&gt;
                  &lt;category&gt;Cat3&lt;/category&gt;
            &lt;/item&gt;
       &lt;/channel&gt;    
  &lt;/root&gt;
  </code></pre>
  
  <p>i have this xml, how i get last category of one item without repeat ?
  i trying:</p>
  
  <pre><code>&lt;?php
          $DOMDocument = new DOMDocument( '1.0', 'utf-8' );
          $DOMDocument-&gt;preserveWhiteSpace = false;
          $DOMDocument-&gt;load( 'xml.xml' );
          $DOMXPath = new DOMXPath( $DOMDocument );
          foreach( $DOMXPath-&gt;query('.//channel/item/category[last()]/parent::node()') as $Nodes ){
                   foreach( $Nodes-&gt;childNodes as $Node ){
                            $RSS[ $Node-&gt;nodeName ] = $Node-&gt;nodeValue;
                   }
                   $RSSContents[] = $RSS;
          }
          echo '&lt;pre&gt;';
          print_r( $RSSContents );
  </code></pre>
  
  <p>But retorning:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [category] =&gt; Cat1
          )
  
      [1] =&gt; Array
          (
              [category] =&gt; Cat1
          )
  
      [2] =&gt; Array
          (
              [category] =&gt; Cat2
          )
  
      [3] =&gt; Array
          (
              [category] =&gt; Cat3
          )
  
  )
  </code></pre>
  
  <p>i need to return last of cat 1 + other items</p>