XPath - Get text from parent using php xpath

Coorieric

New Member
I am trying to get the text from a specific node's parent. For example:\[code\]<td colspan="1" rowspan="1"> <span> <a class="info" shape="rect" rel="empLinkData" href="http://stackoverflow.com/employee.htm?id=8468524"> Jack Johnson </a> </span> (*)&nbsp;</td>\[/code\]I am able to successfully process the anchor tag by using:\[code\]$xNodes = $xpath->query('//a[@class="info"][@rel="empLinkData"]');// $xNodes contains employee ids and namesforeach ($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>'; }}\[/code\]Now, I need to retrieve the text from the \[code\]<td>\[/code\] tag (in this case, the \[code\](*)&nbsp;\[/code\] 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:\[code\]$xNodes = $xpath->query('//a[@class="info"] [@rel="empLinkData"]/ancestor::*');\[/code\]but it is retrieving the wrong data from elsewhere nested above this code.
 
Back
Top