I'm using DOMDocument and DOMXpath to parse an html page.
The markup is like this:
<dl>
<dt>
<a href="">name</a>
</dt>
<dd>
<span class="one">one</span>
<span class="two">two</span>
</dd>
</dl>
<dl>
<dt>
<a href="">name</a>
</dt>
<dd>
<span class="one">one</span>
<span class="two">two</span>
</dd>
</dl>
Originally, I only need to get the href value and was able to use:
$doc = new \DOMDocument();
$doc->loadHTML($html);
$xpath = new \DOMXPath($doc);
$res = $xpath->query('//dl/dt/a');
Then iterate through the results using ->nodeValue
and ->getAttribute('href')
However, now I want to also get the value within the span tag with a class of value of 'two'.
So I updated my query to $xpath->query('//dl')
.
The question is, how would I go about getting the href tag and value now and the span value with the class name. Also, any suggestions on how to debug or display paths to query on would be real helpful.
Thank you!