Reputation: 1820
I am trying to match text, and output the entire row including self in xpath.
The issue I am having is the self node also contains javascript in the html table and it is outputing the script as well.
I have tried the following:
Working but contains javascript from the self node:
$bo_row = $bo_xpath->query( "//td[contains(text(),'1234')]/following-sibling::* | //td[contains(text(),'1234')] " );
Failed attempts all look similar to:
$bo_row = $bo_xpath->query( "//td[contains(text(),'1234')]/following-sibling::* | //td[contains(text(),'1234')]//*[not(self::script)] " );
Here is an example of one table row:
<tr>
<!-- <td><a class=info href="**Missing Data**">
<img src="../images/button_go.gif" border=0>
<span>**Missing Data**</span>
</a>
</td> -->
<script>
if (document.getElementById("Function").value != 'Customer')
document.write('<td><a class=info href="OrdDetLine.pgm?Order=CV780&Page=02&Line=05&Seq=00&ShowPrice=&OpenOnly=&Function=Customer"><img src="../images/button_go.gif" border=0><span>Order Line Detail</span></a></td>');</script>
<td align="left">2-05-00</td>
<td align="left"> 1234
<script>if (document.getElementById("Function").value != 'Customer')
document.write("<a class=info href=#><img src=/operations/images/eye.png border=none onClick=window.open(\'StyleHdr.pgm?CompDiv=CO&Style=1234\'><span>Show style master information panel.</span></a>") ; </script>
</td>
<td align="left">MEN'S LAB/SHOP COATS</td>
<td align="left">REG</td>
<td align="left">NAY</td>
<td align="right">1</td>
<td align="right">April 12, 2019</td>
</tr>
I have tried using getAttribute to select the innertext like so:
$bo_row = $bo_xpath->query( "//tr/td[contains(text(),'1234')]/following-sibling::* | //td[contains(text(),'1234')] " );
echo '<br/>';
if ( $bo_row->length > 0 ) {
foreach ( $bo_row as $row ) {
echo $row->getAttribute ('innerText');
}
However I am either using getAttribute incorrectly or it is not supposed by php as indicated by PHPstorm
Upvotes: 0
Views: 115
Reputation: 14145
You have to use getAttribue('innerText')
. Here is the console output with 2 different approaches.
Upvotes: 0