title: PHP DomXPath to find nested element value
body: <p>I'm using the PHP DOM to extract data from a page and having a hard time getting the href value for a nested element using DomXPath. </p>
  
  <p>Here's my html:</p>
  
  <pre><code>&lt;span class="myclass"&gt;
      &lt;a href="/relative/path"&gt;My Value&lt;/a&gt;
      &lt;span class="otherclass"&gt;&lt;/span&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>And here's my XPath query:</p>
  
  <pre><code>$xpath = new DomXPath($dom);
  $classname = "myclass";
  $nodes = $xpath-&gt;query("//span[contains(@class, '$classname')]");
  
  foreach ($nodes as $node){
      echo $node-&gt;nodeValue;
      echo ",";
      echo $node-&gt;getAttribute('href');
      echo "&lt;br&gt;";
  }
  </code></pre>
  
  <p>I'm able to get the nodeValue just fine ('My Value'), but not the value of the href. I'm sure I'm missing something and not understanding this. Do I need a separate query to get the href value? What's the best way to do this?</p>