QueryPath provides a jQuery-like tool in PHP. Use it to work with local files, or with remote web services. This presentation illustrates how QueryPath can be used to build elaborate multi-source mash-ups in Drupal.
7. Designer/Developer
Dilemma
• Designers create HTML
that is pixel perfect
• Developers are charged
with taking design and
turning it into a web
tool.
• But developers don’t
have the designer’s
skillset.
13. The Task
Find all
<a></a>
tags who have
the ancestor
<div></div>
14. The DOM API
• At least seventeen
classes, each with dozens
of methods.
• Complex data structure.
• Checkered history in
PHP.
• VERY powerful.
15. 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
16. SAX / Expat
Same size,
fewer features
• Event based.
• Write your own parser
handler.
• One per XML format.
• Only reliable “legacy”
library.
17. 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.)
20. The Features
• Query a document • Access remote data
• With XPath • Extensions for...
• CSS selectors • Advanced XML
manipulation (XSLT,
• Move around inside the XSD, PI)
document
• SQL database access
• Modify the document
• Templates
• Access local files
21. CSS 3 Selectors
Source: “Using the QueryPath PHP Library.” Matt Butcher. IBM developerWorks. Mar. 28, 2009
Use CSS Selectors (like in stylesheets) or XPath queries
22. Traversing an
HTML or XML
Document
There are over a dozen
functions for traversing a
document.
These are similar to jQuery’s
traversal functions.
23. Manipulating a
Document
• Get and set text,
elements,
attributes, etc.
• Move, clone,
delete.
• Build arbitrary
XML or HTML.
24. Work with local or
remote sources
• HTML • SPARQL
• SVG images • SOAP
• RSS or Atom • Open Office docs
• Flickr • DBPedia
• Twitter • MusicBrainz
• RDF/Linked Data • ...
25. Extensibility
• One library cannot
provide everything.
• But it can provide an
extension mechanism.
• Developers can integrate
their own code easily.
• You provide the kitchen
sink.
26. Built-in Extensions
• QPDB: QueryPath SQL Database layer
• QPTPL: Template support for QueryPath
• QPXML: Extensions for serious XML
hacking
• More...