About QueryPath
QueryPath is a tool for PHP developers. It is designed to make it easier for software developers to work with XML or HTML documents and web services.
You can use QueryPath to interact with web services from the likes of Flickr, Twitter, and Amazon.com.
You can use it to work with any of the Semantic Web servers.
You can use it to import XML documents into a SQL database, or you can dump SQL results into XML or HTML.
You can write templates in pure HTML, or transform XML into HTML. You can open a document and search it with familiar CSS 3 Selectors or with XPath.
And if you are already familiar with the jQuery JavaScript library, you should be right at home with QueryPath.
Learn more about QueryPath from:
- The API Documentation: Detailed reference information, as well as examples.
- The Wiki: Tutorials and howtos to get you started.
- The main website: The definitive source for news, recent blogs, examples, and, of course, the library itself.
- The source: The QueryPath source code bundle includes dozens of examples, comprehensive unit tests, and well-commented code.
The License(s)
QueryPath is an Open Source PHP library. It is released under a dual license, which means that you (the developer) can decide which license you prefer. The two allowed licenses are:
-
The GNU LGPL, version 2 or later. This license is 100% compatible with the GNU GPL, which means you can include QueryPath in other pieces of software that are licensed under GPL. While the LGPL requires that re-distributed versions of QueryPath be released under the LGPL, there is no viral aspect to this. You can use QueryPath in your own software without then having to release your software under the GPL.
-
An MIT-style license. While we would prefer you not choose this license, you are certainly free to do so. An MIT-style license is less restrictive than the LGPL.
Other QueryPath Content
In addition to the software, there are a few other pieces of content that come with a license:
- All code examples on the site are in public domain. You may use them as you please.
- Text content is Copyright (C) 2009, Matt Butcher. You should ask permission before reprinting significant portions of the site. It is very likely that the content license will be changed to some flavor of Creative Commons license in the future. If you have suggestions, feel free to send them to the QueryPath developers list.
- The QueryPath image is licensed under the Creative Commons Attribution-No Derivative Works 3.0 United States License. Resizing the logo is not considered (by us) to be the creation of a derivative work. Other modifications are.
About the Authors
For the most part, QueryPath was created by Matt Butcher, inspired by jQuery and other similar libraries. Many others, though, have made suggestions, reported bugs, or have just been generally supportive of the project.
There is a rumor floating around that Matt Butcher wrote QueryPath over numerous rides on the Chicago Metra train system. This is absolutely true. It was written in 15-30 minute increments during weekday commutes in Chicago.
How QueryPath Relates to jQuery
It is no accident that QueryPath uses many of jQuery's function names and constructs. A design goal of the project was to make it easy for jQuery programmers to use QueryPath.
Underneath the hood, though, QueryPath is very different. Where jQery takes advantages of all of the quirks and nuances of JavaScript, QueryPath is deeply steeped in the PHP language.
While the jQuery developers have aimed for a tiny file size, QueryPath is spread over multiple files, and exchanges robustness and reusability for compactness. (You can, for example, use our CSS parser in a stand-alone mode.) After all, who cares if the files are slightly larger if they don't have to be sent to a client on each request?
Finally, jQuery is designed to make scripting the browser an easier thing to do. QueryPath is designed for server-side tasks. For example, QueryPath makes it easy to merge multiple XML files into one. It also provides rich access to SQL-based databases. And it can be used just as easily to create HTML, RSS, SVG, RDF, and any other XML format. On the other hand, don't expect to find glitzy browser effects or event models. Those just aren't much use to a server-side developer.
There is no formal relationship between jQuery and QueryPath.
About the Name
Kewpie Doll
The name QueryPath was chosen for a number of reasons. The query part designates the library's ability to query an XML document. The path part is intended to convey the chain-like "path" that one creates through a document when using QueryPath. Incidentally, the original QueryPath did not support XPath, as the current version does.
The main reason that QueryPath was selected as a name, though, has very little to do with technology. it has more to do with my desire to create a function with the signature qp, a homophone of Kewpie. The qp signature has the vague characteristics of a face, with two large eyes and an aquiline nose. I have three daughters. Naming my code after a baby doll seemed appropriate.
The "Philosophy" of QueryPath
QueryPath may not appeal to some OO purists, and certainly will not appeal to purely procedural programmers. Why not? Because in many cases, the library ignores the conventions of the language purist, instead favoring error tolerance, compactness, API compatibility with jQuery, ease of extension development, and pure pragmatism.
For example, staunch OO advocates would insist on using a factory class whose invocation would look something like this:
$factory = new QueryPathFactory(); $qp = $factory->getInstance($filename);
Instead, QueryPath uses this:
$qp = qp($filename);
Along with being more compact, the above is easier to use for method chaining:
qp($filename)->find('title')->text('Hello World.')->writeHTML();
We have not made our decisions lightly, though. In most cases, OO programming principles and design patterns are very good. In fact, we advocate them. But we felt that the departures we made in QueryPath were virtuous departures.
Along with the design decisions we made regarding the API flow and structure, we have made another one: This library has clear boundaries. It is used for traversing and manipulating XML and HTML documents. While we will continue to make releases and fix bugs, we are not going to morph QueryPath into a complex set of libraries to handle all sorts of things. Simplicity is also a design goal, and we adhere to the UNIX tool mantra: "Do one thing very well, and make it easy for others to integrate." To that end, we have added an extension mechanism that should allow others to develop powerful add-on tools.

