How to traverse child elements by xpath in DomNodeList?

955 views Asked by At

I have this PHP script:

<?php
libxml_use_internal_errors(true);
/* Createa a new DomDocument object */
$dom = new DomDocument;
$dom_grep = new DomDocument;
/* Load the HTML */
$dom->loadHTMLFile("http://domain.com/catalog/0_1.html");
/* Create a new XPath object */
$xpath = new DomXPath($dom);
/* Query all <table> nodes containing specified class name */
$nodes = $xpath->query("/html/.//table[@class='right']");
/* Set HTTP response header to plain text for debugging output */
header("Content-type: text/plain");

/* How to make Xpath in code below??? */
foreach ($nodes as $i => $node) {
        $child[$i]["title"] = $node->query("//tr[@class='bg3']//h3");
        $child[$i]["href"] = $node->query("a['href=/catalog/details']");

    }
}
?>

But I got this error in result: "Fatal error: Call to undefined method DOMElement::query()" in $child array

How to make another xpath query in $nodes?

Thank you!

0

There are 0 answers