QueryPath: It's like PHP jQuery in Drupal!

Post on 28-Nov-2014

4.589 views 0 download

description

This slideshow introduces QueryPath (a PHP jQuery library)

Transcript of QueryPath: It's like PHP jQuery in Drupal!

QueryPathIt’s like PHP jQuery for Drupal

http://querypath.orghttp://api.querypath.org

Tuesday, August 17, 2010

Matt ButcherMaintainer of QueryPath

Author of 6 books

Drupal developer atConsumerSearch.Com “Learning Drupal 7” will be

out in RAW this monthhttp://packtpub.com

Tuesday, August 17, 2010

Emily BrandJust completed a

GSoC QueryPath project.MA in Computer Science

IT Developer/EngineerHP

Tuesday, August 17, 2010

What Is QueryPath?

Tuesday, August 17, 2010

A PHP library for working with HTML, XML, and

Web services.

Tuesday, August 17, 2010

Follows the jQuery interfaceas much as possible.

Tuesday, August 17, 2010

Why do we need it?

Tuesday, August 17, 2010

The Task

Find all <a></a>

tags who havethe ancestor

<div></div>

Tuesday, August 17, 2010

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

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 DOMExample

Tuesday, August 17, 2010

SAX / Expat

• Event based.

• Write your own parser handler.

• One per XML format.

• Only reliable “legacy” library.

Same size,fewer features

Tuesday, August 17, 2010

QueryPath

• Compact library.

• Functions are short and mnemonic.

• The power of DOM, but simpler than SimpleXML

• (Shhh... don’t tell, but it’s built on the DOM.)

[This space intentionally left blank ]

Tuesday, August 17, 2010

Lots of Features,One function.

Tuesday, August 17, 2010

• 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);

Files, strings, objects...

Tuesday, August 17, 2010

Search with CSS

qp($rss_url, ‘item > title’);

<?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> 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

Chaining (Fluent API)

Tuesday, August 17, 2010

$qp = new QueryPath(‘my.xml’);$qp->find(‘root’);$qp->append(‘<p>Hi.</p>’)

Tuesday, August 17, 2010

qp(‘my.xml’, ‘root’)->append(‘<p>Hi.</p>’);

Tuesday, August 17, 2010

Some Things it Does• Import/Scrape HTML

• Read XML files

• Remote web services

• SVG image manipulation

• RSS or Atom feeds

• Retrieve database data into XML/HTML

• Work with RDFa

• Run SPARQL queries on Semantic Web

• Generate XML

• Transform using XSLT

• Interact with RDBMS

• And more...

Tuesday, August 17, 2010

QueryPath and Drupal

Tuesday, August 17, 2010

Myth“QueryPath is for Drupal”

QueryPath is a PHP library, and will work with any PHP tool.*

Tuesday, August 17, 2010

FactThe QueryPath Drupal modules

provides all you need.

You can easily use QueryPath within Drupal.

http://drupal.org/project/querypath

Tuesday, August 17, 2010

What’s Been Done with QueryPath?

Tuesday, August 17, 2010

Honestly, I can’t keep track anymore.But here are a few examples.

Tuesday, August 17, 2010

Tuesday, August 17, 2010

Tuesday, August 17, 2010

Tuesday, August 17, 2010

Tuesday, August 17, 2010

Tuesday, August 17, 2010

Tuesday, August 17, 2010

QueryPath 2.1

Tuesday, August 17, 2010

Better HTMLUse

htmlqp() to parse HTML.

Six lines ofcode to grab

headlines fromd.o

Tuesday, August 17, 2010

jQuery 1.4 Features• attach & detach

• has

• even & odd

• first & last

• firstChild & lastChild

• nextUntil, prevUntil & parentsUntil

• More...

Tuesday, August 17, 2010

Tons of new documentation and examples.

Tuesday, August 17, 2010

New Logo

Designed by Michael Mesker

Tuesday, August 17, 2010

And the Drupal module...

Tuesday, August 17, 2010

Drupal 7 version is DONE!

Tuesday, August 17, 2010

Demos

Tuesday, August 17, 2010

• Stable: QueryPath 2.0.1http://querypath.org

• Development: QueryPath 2.1http://github.com/technosophos/querypath

• Drupal modules at http://drupal.org/project/querypath

Tuesday, August 17, 2010