Official homepage http://querypath.org/
QP API Manual http://api.querypath.org/docs/
The QueryPath (QP) library implements effects similar to jQuery in PHP. It can also be used to easily process XML HTML... It’s so powerful! ! !
A QueryPath Tutorial (a simple explanation)
QueryPath makes use of method chaining to provide a concise suite of tools for manipulating a DOM.
The basic principle of method chaining is that each method returns an object upon which additional methods can be called. In our case, the QueryPath object usually returns itself.
Let's take a look at an example to illustrate:
$qp = qp(QueryPath::HTML_STUB); // Generate a new QueryPath object.(Create a QP object)
$qp2 = $qp->find('body'); // Find the body tag.(Find the "body" tag)
// Now the surprising part: (Please see what surprises you below)
if ($qp === $qp2) {
// This will always get printed. (It will always be output like this)
print "MATCH";
}
Why does $qp always equal $qp2? Because the find() function does all of its data gathering and then returns the QueryPath object.
This might seem esoteric, but it all has a very practical rationale. With this sort of interface, we can chain lots of methods together:
(You can chain methods just like using jQuery)
qp(QueryPath::HTML_STUB)->find(' body')->text('Hello World')->writeHTML();
In this example, we have four method calls:
qp(QueryPath::HTML_STUB): Create a new QueryPath object and provide it with a stub of an HTML document. This returns the QueryPath object.
find('body'): This searches the QueryPath document looking for an element named 'body'. That element is, of course, the < body>