I want to select parent or sibling of a node using HTML::TreeBuilder::XPath Perl module, Lets take a sample HTML as follows:
<tbody>
<tr>
<td class="c1">Match_Text</td>
<td class="c2">Extact_Text</td>
</tr>
<tr>
<td class="c1"></td>
<td class="c2"></td>
</tr>
</tbody>
So I want to extract text “Match_Text” for this I give xpath expression as:
'/html/body//td[@class="c1"]="Match_Text"/../td[@class="c2"]'
which is a valid expression for my use case.
But looks like going to parent not implement and I get following error from perl module:
axis axis_parent not implemented [Can’t locate object method
“getParentNode” via package “XML::XPathEngine::Literal” at
/usr/local/share/perl/5.10.1/XML/XPathEngine/Step.pm line 326. ]
Can anyone suggest an alternate Xpath expression that may work for my use case (accessing parent/sibling of a node). Note that I want to do this only using Xpath expression and dont want to create a DOM and explicitly traverse the tree.
The error message is misleading. The problem isn’t lack of support, it’s that you’re trying to find the parent of the boolean returned by the comparison. It doesn’t have one.
You could use