QueryPath is a PHP library for working with HTML, XML, and web services that follows the jQuery interface. It provides a simpler way to work with DOM compared to other PHP libraries like DOM and SimpleXML. QueryPath can be used to search, modify, and extract data from XML/HTML files, strings, and URLs. It has been used in various projects and modules like interacting with Drupal. The latest version adds new features and documentation.
1. QueryPath
It’s like PHP jQuery for Drupal
http://querypath.org
http://api.querypath.org
Tuesday, August 17, 2010
2. Matt Butcher
Maintainer of QueryPath
Author of 6 books
Drupal developer at
ConsumerSearch.Com “Learning Drupal 7” will be
out in RAW this month
http://packtpub.com
Tuesday, August 17, 2010
3. Emily Brand
Just completed a
GSoC QueryPath project.
MA in Computer Science
IT Developer/Engineer
HP
Tuesday, August 17, 2010
8. The Task
Find all
<a></a>
tags who have
the ancestor
<div></div>
Tuesday, August 17, 2010
9. The DOM API
• At least seventeen
classes, each with dozens
of methods.
• Complex data structure.
• Checkered history in
PHP.
• VERY powerful.
Tuesday, August 17, 2010
10. SimpleXML
• One class, about a dozen
functions and methods.
• Turns XML into basic
objects.
• Makes easy stuff easy,
and makes everything
else insanely hard.
Same size as DOM
Example
Tuesday, August 17, 2010
11. SAX / Expat
Same size,
fewer features
• Event based.
• Write your own parser
handler.
• One per XML format.
• Only reliable “legacy”
library.
Tuesday, August 17, 2010
12. QueryPath
• Compact library.
• Functions are short and
mnemonic.
[This space intentionally left blank ]
• The power of DOM, but
simpler than SimpleXML
• (Shhh... don’t tell, but it’s
built on the DOM.)
Tuesday, August 17, 2010
14. Files, strings, objects...
• Open XML/HTML file: qp(‘somefile.xml’);
• Parse string: qp(‘<html>...</html>’);
• Get URL: qp(‘http://drupal.org');
• Use DOM or SimpleXML object: qp($ele);
Tuesday, August 17, 2010
15. Search with CSS
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/"
version="2.0" xml:base="http://technosophos.com">
<channel>
<title>TechnoSophos</title>
<link>http://technosophos.com</link>
<item>
<title>
qp($rss_url, ‘item > title’);
Drupal Dojo: "QueryPath"
</title>
<link>http://technosophos.com/content/...</link>
<description>
On August 17th at 12pm EDT (9AM PDT)...
</description>
</item>
</channel>
</rss>
Tuesday, August 17, 2010
19. Some Things it Does
• Import/Scrape HTML • Work with RDFa
• Read XML files • Run SPARQL queries on
Semantic Web
• Remote web services
• Generate XML
• SVG image manipulation
• Transform using XSLT
• RSS or Atom feeds
• Interact with RDBMS
• Retrieve database data
into XML/HTML • And more...
Tuesday, August 17, 2010
21. Myth
“QueryPath is for Drupal”
QueryPath is a PHP library, and
will work with any PHP tool.*
Tuesday, August 17, 2010
22. Fact
The QueryPath Drupal modules
provides all you need.
You can easily use QueryPath
within Drupal.
http://drupal.org/project/querypath
Tuesday, August 17, 2010