I am trying to get the text from a specific node's parent. For example:
<td colspan="1" rowspan="1">
<span>
<a class="info" shape="rect"
rel="empLinkData" href="/employee.htm?id=8468524">
Jack Johnson
</a>
</span>
(*)
</td>
I am able to successfully process the anchor tag by using:
$xNodes = $xpath->query('//a[@class="info"][@rel="empLinkData"]');
// $xNodes contains employee ids and names
foreach ($xNodes as $xNode)
{
$sLinktext = @$xNode->firstChild->data;
$sLinkurl = 'http://www.company.com' . $xNode->getAttribute('href');
if ($sLinktext != '' && $sLinkurl != '')
{
echo '<li><a href="' . $sLinkurl . '">' .
$sLinktext . '</a></li>';
}
}
Now, I need to retrieve the text from the <td> tag (in this case, the (*) appearing right after the span tag closes), but I can't seem to refer to it properly.
The xpath for this that seems to make the most sense to me is:
$xNodes = $xpath->query('//a[@class="info"]
[@rel="empLinkData"]/ancestor::*');
but it is retrieving the wrong data from elsewhere nested above this code.