I am trying to retrieve certain values using php xpath evaluate or query. But not able to do it successfully.
Here is the html structure of the page:
<div id="productinfo">
<h2>
<span id="productname">Computer</span>
</h2>
<span id="servieidLabel" style=""> Service ID: </span>
<span id="snLabel" style="display: none"> Serial Number: </span>
<span id="servidno">12345ABCD</span>
I want to display only contents with style=”display:none” or if style attribute is not there at all. So that the result is:- Service ID: 12345ABCD.
I have tried:
$ServLab = $xpath->query("//span[@id='servieidLabel']");
foreach ($ServLab as $entry) {
echo "Service Label:" ,$entry->nodeValue."<br />";
}
Output= Service ID:
and
$servid = $xpath->query("//span[@id='servidno']");
foreach ($servid as $entry) {
echo "Service Id No:" ,$entry->nodeValue."<br />";
}
Output = blank. Whereas the output is supposed to 12345ABCD. What am I missing?
If I try:
$prodid = $xpath->evaluate("//div[@id='productinfo']");
foreach ($prodid as $entry) {
echo $entry->nodeValue."<br />";
}
Output = Service ID: Serial Number:
Please help.
The question you stated first could be solved in a single query. Like this one:
This will provide