The Basics of QueryPath

QueryPath is a PHP library resembling jQuery. It implements much of the jQuery API, but it is oriented toward server-side programming. Use it to:

  • Parse XML and HTML
  • Use CSS 3 Selectors to find things
  • Retrieve resources with HTTP and REST
  • Send AJAX information to clients
  • Communicate with web services like Flickr, Amazon, and Twitter
  • Analyze the Semantic Web with Linked Data, RDF and SPARQL
  • Import XML data into a database... or format database information in HTML or XML.

A simple extension mechanism makes adding new features as simple as a few lines of code. And it's all documented.

QueryPath uses succinct and short idioms, making it easy to accomplish complex tasks in only a few lines of code. Here's a sample of QueryPath in action:

<?php
require_once 'QueryPath/QueryPath.php';
 
qp('./test.html')->find('title')->text('Welcome')->writeHTML();
?>

This fragment loads the QueryPath library, and then executes a single jQuery chain. The chain opens a file, test.html, and then finds the <title/> element. The text inside of that element is then set to Welcome, and the entire document is then written to standard out (that is, it is sent to the client).

Read the QueryPath Tutorial for an introduction to QueryPath.

»