SlideShare a Scribd company logo
QueryPath
For Web Services and Mash-ups
• Who created it?
• What does it do?
• Where is it being used?
• Why use it?
• How is it used?
Matt Butcher
 Maintainer of QueryPath and
the Drupal QueryPath module

    http://technosophos.com
http://twitter.com/technosophos
2009
2004
What is QueryPath?


QueryPath is a library for working with
      HTML and XML in PHP.
    It is like jQuery for the Server.
Why Another XML
    Library?
The Task
    Find all
  <a></a>
tags who have
 the ancestor
<div></div>
The DOM API
•   At least seventeen
    classes, each with dozens
    of methods.

•   Complex data structure.

•   Checkered history in
    PHP.

•   VERY powerful.
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
SAX / Expat
               Same size,
             fewer features


•   Event based.

•   Write your own parser
    handler.

•   One per XML format.

•   Only reliable “legacy”
    library.
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.)
Use it to...
•   Import HTML files        •   Create HTML on the fly

•   Read XML files           •   Retrieve database
                                content and insert it
•   Work with remote web        into XML or HTML
    services
                            •   Examine RDFa data
•   Manipulate SVG images       inside HTML or XHTML

•   Retrieve RSS and Atom   •   Run SPARQL queries
    feed data                   and retrieve SemWeb
                                content
Where is it Used?
Importing Content
•   6,000+ existing
    documents

•   Fragments of HTML 2,
    3, and 4

•   Much of it non-standard

•   Imported into Drupal
    using BatchAPI, Tidy, and
    QueryPath
Querying Semantic
        Information
 •   Use the OpenAmplify
     web service

 •   Submit node content

 •   Use results to enrich
     page

 •   Build a supermashup
     (seven web services)

http://www.youtube.com/watch?v=GBBKPIva1tM
Gateway to Web
           Services
•   100’s of Gigabytes of
    data

•   Stored in an external
    Digital Asset
    Management tool

•   XML gateway

•   QueryPath integrates
    Drupal with the DAM
Semantic Network
•   DBPedia is semantic
    equivalent of Wikipedia

•   Query with SPARQL

•   Return semantically
    oriented XML content

•   QueryPath can query
    and make use of the
    results
Twitter Mash-up
•   Retrieve latest posts
    from Twitter

•   Submit them to
    OpenAmplify for analysis

•   Provide “ratings” and
    sentiment information

•   Not in Drupal


                    http://tweetypants.com
Frameweld Framework
•   Frameweld uses
    QueryPath as part of
    their proprietary
    framework

•   Clean separation of
    presentation and other
    logic

•   QueryPath translates
    data objects into HTML   Frameweld contributes
                               back to QueryPath
Why Use It?
Shorten Difficult Tasks
 <?php
 require 'QueryPath/QueryPath.php';

 $odt = 'zip://o.odt#content.xml';

 foreach(qp($odt, 'text|h') as $i) {
   print $i->text() . "n";
 }

(Prints an outline from an ODT document)
Twitter Search



           Ten Lines of Code
How is it Used?
A Closer Look



‣Object-oriented
‣Operates on files, strings, or streams
‣Uses CSS 3 Selectors
‣Has dozens of methods
The Features
•   Query a document         •   Access remote data

    •   With XPath           •   Extensions for...

    •   CSS selectors            •   XSLT, XSD, PI

•   Move around inside the       •   SQL database access
    document
                                 •   Templates
•   Modify the document

•   Access local files
Traversing an
HTML or XML
  Document
   There are over a dozen
  functions for traversing a
         document.

These are similar to jQuery’s
    traversal functions.
Manipulating a
 Document
          •   Get and set text,
              elements,
              attributes, etc.

          •   Move, clone,
              delete.

          •   Build arbitrary
              XML or HTML.
In Drupal...

          •   Install the
              QueryPath
              module

          •   Begin using
              QueryPath in
              your modules
Outside of Drupal

            •   Go to
                QueryPath.org

            •   Download
                QueryPath

            •   Use it in your
                applications
Learn More
• IBM DeveloperWorks published an
  introduction to QueryPath:
  http://is.gd/2wHPA
• The full API docs are available at
  http://api.querypath.org
• Learn more about Drupal modules at
  http://dupal.org/project/querypath

More Related Content

PDF
QueryPath: It's like PHP jQuery in Drupal!
PDF
Why we love ArangoDB. The hunt for the right NosQL Database
KEY
MongoDB, E-commerce and Transactions
PDF
What's brewing in the eZ Systems extensions kitchen
PPTX
JS Essence
PPTX
Shooting rabbits with sling
PDF
Introduction to Python and Django
PDF
Why CouchDB
QueryPath: It's like PHP jQuery in Drupal!
Why we love ArangoDB. The hunt for the right NosQL Database
MongoDB, E-commerce and Transactions
What's brewing in the eZ Systems extensions kitchen
JS Essence
Shooting rabbits with sling
Introduction to Python and Django
Why CouchDB

What's hot (18)

PPTX
Day 2 - Intro to Rails
PDF
NoSQL for great good [hanoi.rb talk]
PPTX
Day 1 - Intro to Ruby
KEY
A rubyist's naive comparison of some database systems and toolkits
PDF
Drupal8 themingdeepdive drupaldevdays-montpellier17042015
KEY
MongoDB and Ecommerce : A perfect combination
PDF
Extbase object to xml mapping
PPTX
Parsing XML & JSON in Apex
PPTX
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
PDF
NoSQL into E-Commerce: lessons learned
PDF
Managing Your Content with Elasticsearch
PDF
Building a spa_in_30min
PPT
Streamlining assessment, feedback, and archival with auto-multiple-choice
PDF
Developing CouchApps
PDF
PyCon 2011 Scaling Disqus
PDF
NoSQL in Perspective
KEY
Lessons from a Dying CMS
PDF
Elasticsearch: You know, for search! and more!
Day 2 - Intro to Rails
NoSQL for great good [hanoi.rb talk]
Day 1 - Intro to Ruby
A rubyist's naive comparison of some database systems and toolkits
Drupal8 themingdeepdive drupaldevdays-montpellier17042015
MongoDB and Ecommerce : A perfect combination
Extbase object to xml mapping
Parsing XML & JSON in Apex
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
NoSQL into E-Commerce: lessons learned
Managing Your Content with Elasticsearch
Building a spa_in_30min
Streamlining assessment, feedback, and archival with auto-multiple-choice
Developing CouchApps
PyCon 2011 Scaling Disqus
NoSQL in Perspective
Lessons from a Dying CMS
Elasticsearch: You know, for search! and more!
Ad

Similar to QueryPath, Mash-ups, and Web Services (20)

PDF
Solr Recipes Workshop
PPT
Apache Content Technologies
KEY
Mashups with Drupal and QueryPath
PDF
Solr Recipes
PDF
Advanced guide to develop ajax applications using dojo
PDF
Rapid API Development ArangoDB Foxx
ODP
If You Have The Content, Then Apache Has The Technology!
PDF
DrupalCampLA 2014 - Drupal backend performance and scalability
PDF
Drupal is not your Website
PDF
Drupal and Apache Stanbol
PDF
Building bridges - Plone Conference 2015 Bucharest
PDF
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
PPTX
Sesi 8_Scraping & API for really bnegineer.pptx
KEY
Library Mashups & APIs
PDF
Drupal Is Not Your Web Site
PPTX
Drupal performance
PDF
Showcasing drupal
PDF
SolrCloud on Hadoop
PDF
RDFa: introduction, comparison with microdata and microformats and how to use it
PDF
Drupal 8 introduction
Solr Recipes Workshop
Apache Content Technologies
Mashups with Drupal and QueryPath
Solr Recipes
Advanced guide to develop ajax applications using dojo
Rapid API Development ArangoDB Foxx
If You Have The Content, Then Apache Has The Technology!
DrupalCampLA 2014 - Drupal backend performance and scalability
Drupal is not your Website
Drupal and Apache Stanbol
Building bridges - Plone Conference 2015 Bucharest
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Sesi 8_Scraping & API for really bnegineer.pptx
Library Mashups & APIs
Drupal Is Not Your Web Site
Drupal performance
Showcasing drupal
SolrCloud on Hadoop
RDFa: introduction, comparison with microdata and microformats and how to use it
Drupal 8 introduction
Ad

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Dropbox Q2 2025 Financial Results & Investor Presentation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Building Integrated photovoltaic BIPV_UPV.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
CIFDAQ's Market Insight: SEC Turns Pro Crypto
The Rise and Fall of 3GPP – Time for a Sabbatical?

QueryPath, Mash-ups, and Web Services

  • 2. • Who created it? • What does it do? • Where is it being used? • Why use it? • How is it used?
  • 3. Matt Butcher Maintainer of QueryPath and the Drupal QueryPath module http://technosophos.com http://twitter.com/technosophos
  • 5. What is QueryPath? QueryPath is a library for working with HTML and XML in PHP. It is like jQuery for the Server.
  • 6. Why Another XML Library?
  • 7. The Task Find all <a></a> tags who have the ancestor <div></div>
  • 8. The DOM API • At least seventeen classes, each with dozens of methods. • Complex data structure. • Checkered history in PHP. • VERY powerful.
  • 9. 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
  • 10. SAX / Expat Same size, fewer features • Event based. • Write your own parser handler. • One per XML format. • Only reliable “legacy” library.
  • 11. 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.)
  • 12. Use it to... • Import HTML files • Create HTML on the fly • Read XML files • Retrieve database content and insert it • Work with remote web into XML or HTML services • Examine RDFa data • Manipulate SVG images inside HTML or XHTML • Retrieve RSS and Atom • Run SPARQL queries feed data and retrieve SemWeb content
  • 13. Where is it Used?
  • 14. Importing Content • 6,000+ existing documents • Fragments of HTML 2, 3, and 4 • Much of it non-standard • Imported into Drupal using BatchAPI, Tidy, and QueryPath
  • 15. Querying Semantic Information • Use the OpenAmplify web service • Submit node content • Use results to enrich page • Build a supermashup (seven web services) http://www.youtube.com/watch?v=GBBKPIva1tM
  • 16. Gateway to Web Services • 100’s of Gigabytes of data • Stored in an external Digital Asset Management tool • XML gateway • QueryPath integrates Drupal with the DAM
  • 17. Semantic Network • DBPedia is semantic equivalent of Wikipedia • Query with SPARQL • Return semantically oriented XML content • QueryPath can query and make use of the results
  • 18. Twitter Mash-up • Retrieve latest posts from Twitter • Submit them to OpenAmplify for analysis • Provide “ratings” and sentiment information • Not in Drupal http://tweetypants.com
  • 19. Frameweld Framework • Frameweld uses QueryPath as part of their proprietary framework • Clean separation of presentation and other logic • QueryPath translates data objects into HTML Frameweld contributes back to QueryPath
  • 21. Shorten Difficult Tasks <?php require 'QueryPath/QueryPath.php'; $odt = 'zip://o.odt#content.xml'; foreach(qp($odt, 'text|h') as $i) { print $i->text() . "n"; } (Prints an outline from an ODT document)
  • 22. Twitter Search Ten Lines of Code
  • 23. How is it Used?
  • 24. A Closer Look ‣Object-oriented ‣Operates on files, strings, or streams ‣Uses CSS 3 Selectors ‣Has dozens of methods
  • 25. The Features • Query a document • Access remote data • With XPath • Extensions for... • CSS selectors • XSLT, XSD, PI • Move around inside the • SQL database access document • Templates • Modify the document • Access local files
  • 26. Traversing an HTML or XML Document There are over a dozen functions for traversing a document. These are similar to jQuery’s traversal functions.
  • 27. Manipulating a Document • Get and set text, elements, attributes, etc. • Move, clone, delete. • Build arbitrary XML or HTML.
  • 28. In Drupal... • Install the QueryPath module • Begin using QueryPath in your modules
  • 29. Outside of Drupal • Go to QueryPath.org • Download QueryPath • Use it in your applications
  • 30. Learn More • IBM DeveloperWorks published an introduction to QueryPath: http://is.gd/2wHPA • The full API docs are available at http://api.querypath.org • Learn more about Drupal modules at http://dupal.org/project/querypath