-
Notifications
You must be signed in to change notification settings - Fork 114
Home
QueryPath is a PHP library resembling jQuery. It implements much of the jQuery API, but it is oriented toward server-side programming. It can be used for parsing or generating HTML and XML (including RSS, SVG, and similar formats). QueryPath can also be used to retrieve XML from web services over HTTP. The QueryPath Database layer provides tools for moving data between XML/HTML files and SQL-based databases. A plugin architecture makes it easy to extend QueryPath’s functionality.
QueryPath uses a chainable API. Following jQuery, it 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 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).
An Introduction to QueryPath will help you get started. (Or, if you want to go from jQuery to QueryPath, you may want to start with this article)
For a more visual introduction to QueryPath, there are a few videos:
- QueryPath and Web Services shows how QueryPath was used to make a supermashup
- Introducing QueryPath introduces coding with QueryPath
- QueryPath: It’s like PHP jQuery in Drupal!
There are various examples and tutorials around the web. Here is a small list. (If you’ve written one, please submit it!)
- ExampleHTMLScraping: Example of web scraping techniques with QueryPath.
- Lots of articles on QueryPath.
- The basics of QueryPath and HTML
- An introduction to Data URLs for embedding images inside of documents.
- Escaping JavaScript in QueryPath
- QueryPath on the Semantic Web: Executing SPARQL from QueryPath
- Replacing Text in one document with that from another (using QueryPath, of course).
- Three part tutorial on using QueryPath to work with an RDBMS using SQL: Part 1 Part 2 Part 3
- The Official API Documentation is online here
You may wish to join one of the two QueryPath groups/lists: