SlideShare a Scribd company logo
High Performance XQuery
Processing in PHP with Zorba




                               Vikram Vaswani
                               November 2012
Vikram Vaswani
Founder, Melonfire
●   Product design and implementation with open source technologies
●   20+ products launched for customers worldwide
Author and active PHP community participant
●   7 books for McGraw-Hill USA
●   250+ tutorials for IBM dW, Zend Developer Zone and others

More information at http://vikram-vaswani.in
XML Support in PHP
●   XML processing: SimpleXML and XMLReader
●   XML transformation: XSLT and XML-DAS
●   Event-based parsing: SAX
●   Tree-based parsing: DOM
●   Serialization: WDDX
●   Dynamic documents: XMLWriter
What's Missing?
Introducing Zorba
●   General purpose XQuery processor for PHP 5.3+
●   Supports XQuery v1.0 and related specifications
●   Available for Windows, Linux, and Mac OS X
●   Open source; Apache 2.0 License
●   Project supported by FLWOR Foundation and
    Oracle.
Supported XML Technologies
●   XPath
●   XQuery v1.0 and v3.0
●   XQuery Scripting
●   Xquery Data Definition
●   XPath Full-Text 1.0
●   XSLT 1.0
●   XqueryX (limited)
PHP Installation
●   Linux and MacOS X
    ●   Libxml2: http://xmlsoft.org/
    ●   Iconv: http://www.gnu.org/software/libiconv/
    ●   libUUID: http://linux.die.net/man/3/libuuid
    ●   ICU (C version): http://www.icu-project.org/
    ●   Xerces (C version): http://xerces.apache.org/xerces-c/
    ●   GCC and related make/cmake utilities
●   Windows
    ●   https://launchpad.net/zorba/+download
●   API Wrapper
    ●   http://zorba.s3.amazonaws.com/ZorbaPHP.zip
PHP Installation
●   Linux and MacOS X
    ●   Libxml2: http://xmlsoft.org/
    ●   Iconv: http://www.gnu.org/software/libiconv/
    ●   libUUID: http://linux.die.net/man/3/libuuid
    ●   ICU (C version): http://www.icu-project.org/
    ●   Xerces (C version): http://xerces.apache.org/xerces-c/
    ●   GCC and related make/cmake utilities
●   Windows
    ●   https://launchpad.net/zorba/+download
●   API Wrapper
    ●   http://zorba.s3.amazonaws.com/ZorbaPHP.zip
Basic Usage
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
try {
    $queryStr = <<<END
    let $message := 'She sells sea shells by the sea shore'
    return
    <result>{$message}</result>
END;
    $query = $zorba->importQuery($queryStr);
    $result = $zorba->execute();
    echo $result;
} catch (Exception $e) {
    die('ERROR:' . $e->getMessage());
}
                                    Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                            http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Basic Usage
Usage Examples
Arithmetic Operators
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<<END
  declare variable $x := 30;
  declare variable $y := 12;
  let $r := $x + $y
  return
  <result> {$r} </result>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                             Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                     http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Sequences
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<<END
 let $dolls := ('Echo', 'Victor', 'Sierra', 'November', 'Alpha')
 return
 <results>
 {
     for $doll in $dolls
     return
     <name>{$doll}</name>
 }
 </results>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                    Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                            http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
String Functions
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<<END
  let $dolls := ('Echo', 'Victor', 'Sierra', 'November', 'Alpha')
  return
  <results>
  {string-join($dolls, ', ')}
  </results>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();




                                  Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                          http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Math Functions
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<<END
 let $set := (1 to 20)
 return
 <results>
 {
       for $i in $set
       where ($i mod 2 eq 0)
       return
       <value> {$i} </value>
 }
 </results>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();

                                           Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                   http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Data Filtering
(XML source)
<?xml version="1.0"?>
<data>
  <record>
    <code>ABW</code>
    <name>Aruba</name>
    <continent>North America</continent>
    <year></year>
    <population>103000</population>
    <gnp>828.00</gnp>
    <capital>
        <name>Oranjestad</name>
        <population>29034</population>
    </capital>
  </record>
  ...
</data>                                  Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                 http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Data Filtering (Simple)
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$dm = $zorba->getXmlDataManager();
$dm->loadDocument('data.xml', file_get_contents('data.xml'));
$queryStr = <<< END
 for $record in doc('data.xml')//record
 let $name := $record/name/text()
 let $code := $record/code/text()
 return
 <name code="{$code}">{$name}</name>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                  Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                          http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Data Filtering (Complex)
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
dm = $zorba->getXmlDataManager();
$dm->loadDocument('data.xml', file_get_contents('data.xml'));
$queryStr = <<< END
 for $record in doc('data.xml')//record
 let $name := $record/name/text()
 let $code := $record/code/text()
 let $population := $record/population/text()
 where contains($record/continent/text(), 'Europe')
 where (xs:integer($population) gt 1000000)
 order by $population descending
 return
 <name code="{$code}" population="{$population}">{$name}</name>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                            Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                    http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Node Manipulation
(XML source, before)
<?xml version='1.0'?>
<heroes>
 <hero>
   <name>Spiderman</name>
   <alterego>Peter Parker</alterego>
 </hero>
 <hero>
   <name>Superman</name>
   <alterego>Clark Kent</alterego>
 </hero>
 <hero>
   <name>The Flash</name>
   <alterego>Wally West</alterego>
 </hero>
</heroes>
                                       Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                               http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Node Manipulation
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$dm = $zorba->getXmlDataManager();
$dm->loadDocument('heroes.xml', file_get_contents('heroes.xml'));
$queryStr = <<< END
 delete node doc('heroes.xml')//heroes/hero[last()],
 replace node doc('heroes.xml')//heroes/hero[last()]
 with
 <hero>
       <name>The Incredible Hulk</name>
       <alterego>Bruce Banner</alterego>
 </hero>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                           Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                   http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Node Manipulation
(XML source, after)
<?xml version="1.0" encoding="UTF-8"?>
<heroes>
 <hero>
    <name>Spiderman</name>
    <alterego>Peter Parker</alterego>
 </hero>
 <hero>
    <name>Superman</name>
    <alterego>Clark Kent</alterego>
 </hero>
 <hero>
    <name>The Incredible Hulk</name>
    <alterego>Bruce Banner</alterego>
 </hero>
</heroes>
                                        Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
REST Parser
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<< END
  import module namespace zorba-rest =
    "http://www.zorba-xquery.com/zorba/rest-functions";
  for $post in
    zorba-rest:get("http://user:pass@api.del.icio.us/v1/posts/recent")//posts/post
  where contains($post/@tag, 'book')
  return
  <result>
    <href> {string($post/@href)} </href>
    <description> {string($post/@description)} </description>
    <tags> {string($post/@tag)} </tags>
  </result>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();

                                            Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                    http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
REST Parser
(After)
<?xml version="1.0" encoding="UTF-8"?>

<result>

 <href>http://www.everythingphpmysql.com/</href>

 <description>How to do Everything with PHP & MySQL - Vikram Vaswani</description>

 <tags>book development php mysql web beginner</tags>

</result>

<result>

 <href>http://www.mysql-tcr.com/</href>

 <description>MySQL: The Complete Reference - Vikram Vaswani</description>

 <tags>mysql php book</tags>

</result>
JSON Parser
(JSON source)
{
    "books": [{
     "title":"Phantom Prey",
     "author":"John Sandford",
     "price":"7.99"
    }, {
     "title":"A Most Wanted Man",
     "author":"John le Carre",
     "price":"8.99"
    },{
     "title":"Beach Babylon",
     "author":"Imogen Edward-Jones",
     "price":"12.99"
    }]
}
                                       Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                               http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
JSON Parser
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<< END
 import module namespace json =
         "http://www.zorba-xquery.com/zorba/json-functions";
       let $x := json:parse('{$json}')
       for $i in $x//item
       where (xs:decimal($i/pair[@name='price']/text()) lt 10.00)
       return
       <result> {$i/pair[@name='title']/text()} </result>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                    Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                            http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
JSON Parser
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<< END
 import module namespace json =
         "http://www.zorba-xquery.com/zorba/json-functions";
       let $x := json:parse('{$json}')
       for $i in $x//item
       where (xs:decimal($i/pair[@name='price']/text()) lt 10.00)
       return
       <result> {$i/pair[@name='title']/text()} </result>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                    Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                            http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Performance
Scenario
●   Data
    ●   1 day of forecast data in XML format: 727MB
●   Workflow
    ●   Process data for a specific site
    ●   Send selected temperatures to clients
    ●   Display chart




                                    Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
SimpleXML
<?php
$siteId = 3;


$forecasts = simplexml_load_file('forecasts.xml');
$forecasts = $forecasts->xpath(
    "/forecast-list/forecast[@site-id='$siteId']");


foreach($forecasts as$forecast) {
    $time = $forecast->xpath("@time-step");
    $value = $forecast->xpath(
      "//weather-elements/weather-element"
      ."[@name = 'ScreenTemperature']/text()");
    echo "<temperature time='" . $time[0] ."'value='" = . $value[0] . "' />n";
}
?>

                                             Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                         http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
Zorba
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();


$queryStr = <<<END
  for $forecast inz:parse-xml(file:read-text("forecasts.xml"),
    <opt:options>
    <opt:parseExternalParsedEntity opt:skipRootNodes="1"/>
    </opt:options>)
  where $forecast/@site-id = "3"
  let $time:= string($forecast/@time-step)
  let $value:= $forecast/weather-elements/weather-element
    [@name = 'ScreenTemperature']/text()
  return
  <temperaturetime="{$time}" value="{$value}" />
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();

                                                 Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                             http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
Results

                            10000

                                      9000
                            9000

                            8000
  Memory Consumption (MB)




                            7000

                            6000

                            5000

                            4000

                            3000

                            2000

                            1000

                                                                                                      19
                               0
                                    SimpleXML                                                       Zorba
                                                   PHP Extension


                                                    Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                                http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
AWS Libraries

                10000

                9000    8589

                8000

                7000
Lines of Code




                6000

                5000
                                                                                                                              Java
                4000                                                                                                          XQuery

                                              2905
                3000
                                                                                      2309
                2000                1469
                1000                                       572                                       455
                   0
                               S3                SimpleDB                                    SNS

                                           AWS Libraries




                                                     Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                                 http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
Resources
●   Usage docs: zorba-xquery.com/html/documentation
●   Live demo: zorba-xquery.com/html/demo
●   Source code: code.launchpad.net/~zorba-
    coders/zorba/trunk
●   Modules: zorba-xquery.com/html/modules
●   Toolkit: xqdt.org
●   Forums: zorba-users [at] googlegroups [dot] com
●   News: zorba-xquery.com/html/blog
●   Twitter: @wcandillon
Questions?
Contact Information
Email:
●   vikram-vaswani.in/contact
Web:
●   www.melonfire.com
●   vikram-vaswani.in
Social networks:
●   plus.google.com/100028886433648406825
●   twitter.com/melonfire

More Related Content

What's hot

KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天
tblanlan
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
eugenio pombi
 
The state of your own hypertext preprocessor
The state of your own hypertext preprocessorThe state of your own hypertext preprocessor
The state of your own hypertext preprocessor
Alessandro Nadalin
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEB
Howard Lewis Ship
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
Remy Sharp
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Adrien Guéret
 
Immutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS LambdaImmutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS Lambda
AOE
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearch
Pedro Franceschi
 
Fatc
FatcFatc
MongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksMongoDB: tips, trick and hacks
MongoDB: tips, trick and hacks
Scott Hernandez
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
Gabriele Lana
 
Scala active record
Scala active recordScala active record
Scala active record
鉄平 土佐
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
Simon Su
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
deimos
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 

What's hot (19)

KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
The state of your own hypertext preprocessor
The state of your own hypertext preprocessorThe state of your own hypertext preprocessor
The state of your own hypertext preprocessor
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEB
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Immutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS LambdaImmutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS Lambda
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearch
 
Fatc
FatcFatc
Fatc
 
MongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksMongoDB: tips, trick and hacks
MongoDB: tips, trick and hacks
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Scala active record
Scala active recordScala active record
Scala active record
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 

Similar to High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani

[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
 
Sprockets
SprocketsSprockets
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
Boris Nadion
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and Ops
Mykyta Protsenko
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
Jeffrey Zinn
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
James Titcumb
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Nick Sieger
 
Express Presentation
Express PresentationExpress Presentation
Express Presentation
aaronheckmann
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays
 
WCLV13 JavaScript
WCLV13 JavaScriptWCLV13 JavaScript
WCLV13 JavaScript
Jeffrey Zinn
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
Achieve Internet
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
s_pradeep
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccion
Sysdig
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
Aaronius
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
Fabien Potencier
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
Yoann Gotthilf
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
Ngoc Dao
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
Willian Molinari
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 

Similar to High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani (20)

[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Sprockets
SprocketsSprockets
Sprockets
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and Ops
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Express Presentation
Express PresentationExpress Presentation
Express Presentation
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
 
WCLV13 JavaScript
WCLV13 JavaScriptWCLV13 JavaScript
WCLV13 JavaScript
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccion
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 

Recently uploaded

Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and ConsiderationsChoosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
webbyacad software
 
NVIDIA at Breakthrough Discuss for Space Exploration
NVIDIA at Breakthrough Discuss for Space ExplorationNVIDIA at Breakthrough Discuss for Space Exploration
NVIDIA at Breakthrough Discuss for Space Exploration
Alison B. Lowndes
 
Latest Tech Trends Series 2024 By EY India
Latest Tech Trends Series 2024 By EY IndiaLatest Tech Trends Series 2024 By EY India
Latest Tech Trends Series 2024 By EY India
EYIndia1
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
shyamraj55
 
Accelerating Migrations = Recommendations
Accelerating Migrations = RecommendationsAccelerating Migrations = Recommendations
Accelerating Migrations = Recommendations
isBullShit
 
Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10
ankush9927
 
Keynote : Presentation on SASE Technology
Keynote : Presentation on SASE TechnologyKeynote : Presentation on SASE Technology
Keynote : Presentation on SASE Technology
Priyanka Aash
 
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Zilliz
 
Required Documents for ISO 17021 Certification.PPT
Required Documents for ISO 17021 Certification.PPTRequired Documents for ISO 17021 Certification.PPT
Required Documents for ISO 17021 Certification.PPT
mithun772
 
Acumatica vs. Sage Intacct _Construction_July (1).pptx
Acumatica vs. Sage Intacct _Construction_July (1).pptxAcumatica vs. Sage Intacct _Construction_July (1).pptx
Acumatica vs. Sage Intacct _Construction_July (1).pptx
BrainSell Technologies
 
Zaitechno Handheld Raman Spectrometer.pdf
Zaitechno Handheld Raman Spectrometer.pdfZaitechno Handheld Raman Spectrometer.pdf
Zaitechno Handheld Raman Spectrometer.pdf
AmandaCheung15
 
The Path to General-Purpose Robots - Coatue
The Path to General-Purpose Robots - CoatueThe Path to General-Purpose Robots - Coatue
The Path to General-Purpose Robots - Coatue
Razin Mustafiz
 
Intel Unveils Core Ultra 200V Lunar chip .pdf
Intel Unveils Core Ultra 200V Lunar chip .pdfIntel Unveils Core Ultra 200V Lunar chip .pdf
Intel Unveils Core Ultra 200V Lunar chip .pdf
Tech Guru
 
Demystifying Neural Networks And Building Cybersecurity Applications
Demystifying Neural Networks And Building Cybersecurity ApplicationsDemystifying Neural Networks And Building Cybersecurity Applications
Demystifying Neural Networks And Building Cybersecurity Applications
Priyanka Aash
 
COVID-19 and the Level of Cloud Computing Adoption: A Study of Sri Lankan Inf...
COVID-19 and the Level of Cloud Computing Adoption: A Study of Sri Lankan Inf...COVID-19 and the Level of Cloud Computing Adoption: A Study of Sri Lankan Inf...
COVID-19 and the Level of Cloud Computing Adoption: A Study of Sri Lankan Inf...
AimanAthambawa1
 
Connector Corner: Leveraging Snowflake Integration for Smarter Decision Making
Connector Corner: Leveraging Snowflake Integration for Smarter Decision MakingConnector Corner: Leveraging Snowflake Integration for Smarter Decision Making
Connector Corner: Leveraging Snowflake Integration for Smarter Decision Making
DianaGray10
 
Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17
Bhajan Mehta
 
Improving Learning Content Efficiency with Reusable Learning Content
Improving Learning Content Efficiency with Reusable Learning ContentImproving Learning Content Efficiency with Reusable Learning Content
Improving Learning Content Efficiency with Reusable Learning Content
Enterprise Knowledge
 
Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...
Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...
Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...
Snarky Security
 
Mastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for SuccessMastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for Success
David Wilson
 

Recently uploaded (20)

Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and ConsiderationsChoosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
 
NVIDIA at Breakthrough Discuss for Space Exploration
NVIDIA at Breakthrough Discuss for Space ExplorationNVIDIA at Breakthrough Discuss for Space Exploration
NVIDIA at Breakthrough Discuss for Space Exploration
 
Latest Tech Trends Series 2024 By EY India
Latest Tech Trends Series 2024 By EY IndiaLatest Tech Trends Series 2024 By EY India
Latest Tech Trends Series 2024 By EY India
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
 
Accelerating Migrations = Recommendations
Accelerating Migrations = RecommendationsAccelerating Migrations = Recommendations
Accelerating Migrations = Recommendations
 
Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10
 
Keynote : Presentation on SASE Technology
Keynote : Presentation on SASE TechnologyKeynote : Presentation on SASE Technology
Keynote : Presentation on SASE Technology
 
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
 
Required Documents for ISO 17021 Certification.PPT
Required Documents for ISO 17021 Certification.PPTRequired Documents for ISO 17021 Certification.PPT
Required Documents for ISO 17021 Certification.PPT
 
Acumatica vs. Sage Intacct _Construction_July (1).pptx
Acumatica vs. Sage Intacct _Construction_July (1).pptxAcumatica vs. Sage Intacct _Construction_July (1).pptx
Acumatica vs. Sage Intacct _Construction_July (1).pptx
 
Zaitechno Handheld Raman Spectrometer.pdf
Zaitechno Handheld Raman Spectrometer.pdfZaitechno Handheld Raman Spectrometer.pdf
Zaitechno Handheld Raman Spectrometer.pdf
 
The Path to General-Purpose Robots - Coatue
The Path to General-Purpose Robots - CoatueThe Path to General-Purpose Robots - Coatue
The Path to General-Purpose Robots - Coatue
 
Intel Unveils Core Ultra 200V Lunar chip .pdf
Intel Unveils Core Ultra 200V Lunar chip .pdfIntel Unveils Core Ultra 200V Lunar chip .pdf
Intel Unveils Core Ultra 200V Lunar chip .pdf
 
Demystifying Neural Networks And Building Cybersecurity Applications
Demystifying Neural Networks And Building Cybersecurity ApplicationsDemystifying Neural Networks And Building Cybersecurity Applications
Demystifying Neural Networks And Building Cybersecurity Applications
 
COVID-19 and the Level of Cloud Computing Adoption: A Study of Sri Lankan Inf...
COVID-19 and the Level of Cloud Computing Adoption: A Study of Sri Lankan Inf...COVID-19 and the Level of Cloud Computing Adoption: A Study of Sri Lankan Inf...
COVID-19 and the Level of Cloud Computing Adoption: A Study of Sri Lankan Inf...
 
Connector Corner: Leveraging Snowflake Integration for Smarter Decision Making
Connector Corner: Leveraging Snowflake Integration for Smarter Decision MakingConnector Corner: Leveraging Snowflake Integration for Smarter Decision Making
Connector Corner: Leveraging Snowflake Integration for Smarter Decision Making
 
Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17
 
Improving Learning Content Efficiency with Reusable Learning Content
Improving Learning Content Efficiency with Reusable Learning ContentImproving Learning Content Efficiency with Reusable Learning Content
Improving Learning Content Efficiency with Reusable Learning Content
 
Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...
Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...
Welcome to Cyberbiosecurity. Because regular cybersecurity wasn't complicated...
 
Mastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for SuccessMastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for Success
 

High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani

  • 1. High Performance XQuery Processing in PHP with Zorba Vikram Vaswani November 2012
  • 2. Vikram Vaswani Founder, Melonfire ● Product design and implementation with open source technologies ● 20+ products launched for customers worldwide Author and active PHP community participant ● 7 books for McGraw-Hill USA ● 250+ tutorials for IBM dW, Zend Developer Zone and others More information at http://vikram-vaswani.in
  • 3. XML Support in PHP ● XML processing: SimpleXML and XMLReader ● XML transformation: XSLT and XML-DAS ● Event-based parsing: SAX ● Tree-based parsing: DOM ● Serialization: WDDX ● Dynamic documents: XMLWriter
  • 5. Introducing Zorba ● General purpose XQuery processor for PHP 5.3+ ● Supports XQuery v1.0 and related specifications ● Available for Windows, Linux, and Mac OS X ● Open source; Apache 2.0 License ● Project supported by FLWOR Foundation and Oracle.
  • 6. Supported XML Technologies ● XPath ● XQuery v1.0 and v3.0 ● XQuery Scripting ● Xquery Data Definition ● XPath Full-Text 1.0 ● XSLT 1.0 ● XqueryX (limited)
  • 7. PHP Installation ● Linux and MacOS X ● Libxml2: http://xmlsoft.org/ ● Iconv: http://www.gnu.org/software/libiconv/ ● libUUID: http://linux.die.net/man/3/libuuid ● ICU (C version): http://www.icu-project.org/ ● Xerces (C version): http://xerces.apache.org/xerces-c/ ● GCC and related make/cmake utilities ● Windows ● https://launchpad.net/zorba/+download ● API Wrapper ● http://zorba.s3.amazonaws.com/ZorbaPHP.zip
  • 8. PHP Installation ● Linux and MacOS X ● Libxml2: http://xmlsoft.org/ ● Iconv: http://www.gnu.org/software/libiconv/ ● libUUID: http://linux.die.net/man/3/libuuid ● ICU (C version): http://www.icu-project.org/ ● Xerces (C version): http://xerces.apache.org/xerces-c/ ● GCC and related make/cmake utilities ● Windows ● https://launchpad.net/zorba/+download ● API Wrapper ● http://zorba.s3.amazonaws.com/ZorbaPHP.zip
  • 9. Basic Usage <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); try { $queryStr = <<<END let $message := 'She sells sea shells by the sea shore' return <result>{$message}</result> END; $query = $zorba->importQuery($queryStr); $result = $zorba->execute(); echo $result; } catch (Exception $e) { die('ERROR:' . $e->getMessage()); } Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 12. Arithmetic Operators <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END declare variable $x := 30; declare variable $y := 12; let $r := $x + $y return <result> {$r} </result> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 13. Sequences <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END let $dolls := ('Echo', 'Victor', 'Sierra', 'November', 'Alpha') return <results> { for $doll in $dolls return <name>{$doll}</name> } </results> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 14. String Functions <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END let $dolls := ('Echo', 'Victor', 'Sierra', 'November', 'Alpha') return <results> {string-join($dolls, ', ')} </results> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 15. Math Functions <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END let $set := (1 to 20) return <results> { for $i in $set where ($i mod 2 eq 0) return <value> {$i} </value> } </results> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 16. Data Filtering (XML source) <?xml version="1.0"?> <data> <record> <code>ABW</code> <name>Aruba</name> <continent>North America</continent> <year></year> <population>103000</population> <gnp>828.00</gnp> <capital> <name>Oranjestad</name> <population>29034</population> </capital> </record> ... </data> Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 17. Data Filtering (Simple) <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $dm = $zorba->getXmlDataManager(); $dm->loadDocument('data.xml', file_get_contents('data.xml')); $queryStr = <<< END for $record in doc('data.xml')//record let $name := $record/name/text() let $code := $record/code/text() return <name code="{$code}">{$name}</name> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 18. Data Filtering (Complex) <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); dm = $zorba->getXmlDataManager(); $dm->loadDocument('data.xml', file_get_contents('data.xml')); $queryStr = <<< END for $record in doc('data.xml')//record let $name := $record/name/text() let $code := $record/code/text() let $population := $record/population/text() where contains($record/continent/text(), 'Europe') where (xs:integer($population) gt 1000000) order by $population descending return <name code="{$code}" population="{$population}">{$name}</name> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 19. Node Manipulation (XML source, before) <?xml version='1.0'?> <heroes> <hero> <name>Spiderman</name> <alterego>Peter Parker</alterego> </hero> <hero> <name>Superman</name> <alterego>Clark Kent</alterego> </hero> <hero> <name>The Flash</name> <alterego>Wally West</alterego> </hero> </heroes> Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 20. Node Manipulation <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $dm = $zorba->getXmlDataManager(); $dm->loadDocument('heroes.xml', file_get_contents('heroes.xml')); $queryStr = <<< END delete node doc('heroes.xml')//heroes/hero[last()], replace node doc('heroes.xml')//heroes/hero[last()] with <hero> <name>The Incredible Hulk</name> <alterego>Bruce Banner</alterego> </hero> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 21. Node Manipulation (XML source, after) <?xml version="1.0" encoding="UTF-8"?> <heroes> <hero> <name>Spiderman</name> <alterego>Peter Parker</alterego> </hero> <hero> <name>Superman</name> <alterego>Clark Kent</alterego> </hero> <hero> <name>The Incredible Hulk</name> <alterego>Bruce Banner</alterego> </hero> </heroes> Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 22. REST Parser <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<< END import module namespace zorba-rest = "http://www.zorba-xquery.com/zorba/rest-functions"; for $post in zorba-rest:get("http://user:pass@api.del.icio.us/v1/posts/recent")//posts/post where contains($post/@tag, 'book') return <result> <href> {string($post/@href)} </href> <description> {string($post/@description)} </description> <tags> {string($post/@tag)} </tags> </result> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 23. REST Parser (After) <?xml version="1.0" encoding="UTF-8"?> <result> <href>http://www.everythingphpmysql.com/</href> <description>How to do Everything with PHP & MySQL - Vikram Vaswani</description> <tags>book development php mysql web beginner</tags> </result> <result> <href>http://www.mysql-tcr.com/</href> <description>MySQL: The Complete Reference - Vikram Vaswani</description> <tags>mysql php book</tags> </result>
  • 24. JSON Parser (JSON source) { "books": [{ "title":"Phantom Prey", "author":"John Sandford", "price":"7.99" }, { "title":"A Most Wanted Man", "author":"John le Carre", "price":"8.99" },{ "title":"Beach Babylon", "author":"Imogen Edward-Jones", "price":"12.99" }] } Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 25. JSON Parser <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<< END import module namespace json = "http://www.zorba-xquery.com/zorba/json-functions"; let $x := json:parse('{$json}') for $i in $x//item where (xs:decimal($i/pair[@name='price']/text()) lt 10.00) return <result> {$i/pair[@name='title']/text()} </result> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 26. JSON Parser <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<< END import module namespace json = "http://www.zorba-xquery.com/zorba/json-functions"; let $x := json:parse('{$json}') for $i in $x//item where (xs:decimal($i/pair[@name='price']/text()) lt 10.00) return <result> {$i/pair[@name='title']/text()} </result> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 28. Scenario ● Data ● 1 day of forecast data in XML format: 727MB ● Workflow ● Process data for a specific site ● Send selected temperatures to clients ● Display chart Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 29. SimpleXML <?php $siteId = 3; $forecasts = simplexml_load_file('forecasts.xml'); $forecasts = $forecasts->xpath( "/forecast-list/forecast[@site-id='$siteId']"); foreach($forecasts as$forecast) { $time = $forecast->xpath("@time-step"); $value = $forecast->xpath( "//weather-elements/weather-element" ."[@name = 'ScreenTemperature']/text()"); echo "<temperature time='" . $time[0] ."'value='" = . $value[0] . "' />n"; } ?> Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 30. Zorba <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END for $forecast inz:parse-xml(file:read-text("forecasts.xml"), <opt:options> <opt:parseExternalParsedEntity opt:skipRootNodes="1"/> </opt:options>) where $forecast/@site-id = "3" let $time:= string($forecast/@time-step) let $value:= $forecast/weather-elements/weather-element [@name = 'ScreenTemperature']/text() return <temperaturetime="{$time}" value="{$value}" /> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 31. Results 10000 9000 9000 8000 Memory Consumption (MB) 7000 6000 5000 4000 3000 2000 1000 19 0 SimpleXML Zorba PHP Extension Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 32. AWS Libraries 10000 9000 8589 8000 7000 Lines of Code 6000 5000 Java 4000 XQuery 2905 3000 2309 2000 1469 1000 572 455 0 S3 SimpleDB SNS AWS Libraries Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 33. Resources ● Usage docs: zorba-xquery.com/html/documentation ● Live demo: zorba-xquery.com/html/demo ● Source code: code.launchpad.net/~zorba- coders/zorba/trunk ● Modules: zorba-xquery.com/html/modules ● Toolkit: xqdt.org ● Forums: zorba-users [at] googlegroups [dot] com ● News: zorba-xquery.com/html/blog ● Twitter: @wcandillon
  • 35. Contact Information Email: ● vikram-vaswani.in/contact Web: ● www.melonfire.com ● vikram-vaswani.in Social networks: ● plus.google.com/100028886433648406825 ● twitter.com/melonfire