title: domXpath get ancestor node
body: <p>I have the following html structure :</p>
  
  <pre><code>&lt;a class="class1" href="link"&gt;
     &lt;div class="class2" id="result_0"&gt;
        &lt;img imgstuffhere /&gt;      
           &lt;div class="class3"&gt;
             &lt;span&gt;text&lt;/span&gt;
          &lt;/div&gt;
     &lt;/div&gt;
  &lt;/a&gt;
  &lt;a class="class1" href="link"&gt;
     &lt;div class="class2" id="result_0"&gt;
        &lt;img imgstuffhere /&gt;      
           &lt;div class="class3"&gt;
             &lt;span&gt;text&lt;/span&gt;
          &lt;/div&gt;
     &lt;/div&gt;
  &lt;/a&gt;
  etc....
  </code></pre>
  
  <p>I'm parsing the page using domXPath. I'm able to get each block by doing </p>
  
  <pre><code>$items = $xpath-&gt;query("//*[contains(concat(' ', normalize-space(@class), ' '), ' class1 ')]");
  </code></pre>
  
  <p>then i loop on items set of results :</p>
  
  <pre><code>foreach($items as $item){
      $name = $xpath-&gt;query("descendant::*[contains(concat(' ', normalize-space(@class), ' '), ' class3 ')]", $item)-&gt;item(0)-&gt;nodeValue;
      etc...
  }
  </code></pre>
  
  <p>My problem is, in the loop, i need to get the href link located in the class1  node.</p>
  
  <p>I tried to play around with ancestor stuff, but impossible to make it works.</p>
  
  <p><strong>ANSWER</strong></p>
  
  <pre><code>$link = $item-&gt;getAttribute('href');
  </code></pre>
  
  <p>Simply did the trick.</p>