> The XQuery Processor
<?php /* * Copyright 2006-2008 The FLWOR Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ require '/home/pfkeb/zorba/branches/0.9.5-rc1/doc/php/examples/zorba_api.php'; function example_1(Zorba $aZorba) { $lQuery = $aZorba->compileQuery('1+1'); echo $lQuery->execute(); $lQuery->destroy(); return true; } function example_2(Zorba $aZorba) { $lQuery = $aZorba->compileQuery('1+1'); $lIterator = $lQuery->iterator(); $lIterator->open(); $lItem = Item::createEmptyItem(); while($lIterator->next($lItem)) { echo $lItem->getStringValue() . "\n"; } $lIterator->close(); $lIterator->destroy(); $lQuery->destroy(); return true; } function example_3(Zorba $aZorba) { $lQuery = $aZorba->compileQuery('1 div 0'); try { echo $lQuery->execute(); } catch ( Exception $e ) { echo $e->getMessage() . "\n"; $lQuery->destroy(); return true; } $lQuery->destroy(); return false; } function example_4(Zorba $aZorba) { try { $lQuery = $aZorba->compileQuery('for $i in (1,2,3)'); } catch ( Exception $e ) { echo $e->getMessage() . "\n"; return true; } return false; } function example_5(Zorba $aZorba) { $lDataManager = $aZorba->getXmlDataManager(); $lDataManager->loadDocument("books.xml", "<books><book>Book 1</book><book>Book 2</book></books>"); $lQuery = $aZorba->compileQuery("doc('books.xml')//book"); echo $lQuery->execute(); $lQuery->destroy(); return true; } function example_6(Zorba $aZorba) { $lDataManager = $aZorba->getXmlDataManager(); $lDataManager->loadDocument("books.xml", "<books><book>Book 1</book><book>Book 2</book></books>"); $lQuery1 = $aZorba->compileQuery("insert node <book>Book 3</book> into doc('books.xml')/books"); if($lQuery1->isUpdateQuery()) { $lQuery1->applyUpdates(); } $lQuery2 = $aZorba->compileQuery("doc('books.xml')//book"); echo $lQuery2->execute(); $lQuery1->destroy(); $lQuery2->destroy(); return true; } $store = InMemoryStore::getInstance(); $zorba = Zorba::getInstance($store); print "Example1:\n"; $res = example_1($zorba); assert($res); print "\n\n"; print "Example2:\n"; $res = example_2($zorba); assert($res); print "\n\n"; print "Example3:\n"; $res = example_3($zorba); assert($res); print "\n\n"; print "Example4:\n"; $res = example_4($zorba); assert($res); print "\n\n"; print "Example5:\n"; $res = example_5($zorba); assert($res); print "\n\n"; print "Example6:\n"; $res = example_6($zorba); assert($res); print "\n\n"; $zorba->shutdown(); InMemoryStore::shutdown($store); ?>