3

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!

  • Well, I assume you pressed the "submit question" button a little too soon. Your actual question seems to have been cut off. :-) – Marcus Rickert Dec 05 '13 at 20:19
  • In first query I'm searching part of code like some DIV or TABLE etc.In second query I need to find nodes, node values or node attributes (it depends of input arguments) which were passed in script as xpath. So I need to make Xpath in already selected part of HTML (DomNodeList). – user3061744 Dec 05 '13 at 20:28
  • Using terms such as _like some DIV or TABLE etc_ is not really a good idea as a part of a question at StackOverflow. If you question is vague the answers will be, too. Be more precise: What _does not work_ about your script? What do you _expect_? – Marcus Rickert Dec 05 '13 at 20:34
  • I've changed original question. Is it more clear now? – user3061744 Dec 06 '13 at 09:49
  • I think it is. You want to make relative subqueries starting in a previously selected node. You actually need to know to things: a) What is the XPath expression for a relative query, and b) how do you call the query PHP-wise? Correct? – Marcus Rickert Dec 06 '13 at 10:13
  • All xpath queries are correct. "how do you call the query PHP-wise? Correct?" - What do you mean? As you said, the question about relative subqueries in PHP. So, I'm asking exactly about it. – user3061744 Dec 06 '13 at 14:10
  • So your XPath expressions work? Then why do you write _How to make Xpath in code below???_ in your source code? – Marcus Rickert Dec 06 '13 at 14:22
  • The problem is $nodes or $node as DomNodeList doesn't support query() method. So, I need to resolve this, I need to make another query in DomNodeList. How can I resolve this situation? – user3061744 Dec 06 '13 at 14:26
  • Possible duplicate of [How do I do an XPath query on a DOMNode?](https://stackoverflow.com/questions/16727378/how-do-i-do-an-xpath-query-on-a-domnode) – Jeff Puckett Dec 29 '17 at 05:12

0 Answers0