PheXist is a set of classes (PHP5, PHP4 & Perl) to query and manipulate XML documents in eXist XML:DB.
eXist is an Open Source native XML database featuring efficient, index-based XQuery processing, automatic indexing, extensions for full-text search, XUpdate support and tight integration with existing XML development tools.
This set of classes, implemented in both PHP and Perl, allow to query the XML:DB using the XQuery language.
Connection with XML:DB is done through a SOAP interface, using a WSDL defintion (see: http://localhost:8080/exist/services/Query?wsdl)
Class methods
public function store($data, $encoding = "UTF-8", $path = "/db", $replace = false) public function removeDocument($path) public function createCollection($path) public function removeCollection($path) public function xupdate($collectionName, $xupdate) public function xupdateResource($documentName, $xupdate) ( Instead of using the above xupdate methods, I would recommend using XQuery update extensions. See: http://exist.sourceforge.net/update_ext.html ) // TODO : getCollectionDesc // TODO : getBinaryResource
2006-06-08 : Version 0.4
2006-02-15 : Version 0.3
2005-07-20 : Version 0.2
2005-03-21 : Version 0.1
PHP5:
PHP4 (deprecated):
Perl (deprecated):
<?php include ('include/eXist.php'); # # (1) XQuery example # try { $db = new eXist(); # Connect $db->connect() or die ($db->getError()); $query = 'for $line in //SPEECH[SPEAKER = "BERNARDO"]/LINE return $line'; print "<p><b>XQuery:</b></p><pre>$query</pre>"; # XQuery execution //$db->setDebug(TRUE); $db->setHighlight(FALSE); $result = $db->xquery($query) or die ($db->getError()); # Get results $hits = $result["HITS"]; $queryTime = $result["QUERY_TIME"]; $collections = $result["COLLECTIONS"]; print "<p>found $hits hits in $queryTime ms.</p>"; # Show results print "<p><b>Result of the XQuery:</b></p>"; print "<pre>"; if ( !empty($result["XML"]) ) foreach ( $result["XML"] as $xml) print htmlspecialchars($xml) . "<br />"; print "</pre>"; $db->disconnect() or die ($db->getError()); } catch( Exception $e ) { die($e); } # # (2) Adding/removing documents and collections # try { $db = new eXistAdmin('guest', 'guest', 'http://127.0.0.1:8080/exist/services/Admin?wsdl'); $db->connect() or die ($db->getError()); // Store Document $db->store('<simple><fxp>françois</fxp></simple>', 'UTF-8', '/db/test.xml', true); $db->store('<simple><fxp>françois</fxp></simple>', 'UTF-8', '/db/test2suppr.xml', true); // Remove Document $db->removeDocument('/db/test2suppr.xml'); // Create collection $db->createCollection('/db/existAdminDemo'); $db->createCollection('/db/existAdminDemo2supp'); // Remove collection $db->removeCollection('/db/existAdminDemo2supp'); /* // Better to use XQuery update extensions (see: http://exist.sourceforge.net/update_ext.html) // XupdateResource $xupdate = "<xupdate:modifications version='1.0' xmlns:xupdate='http://www.xmldb.org/xupdate'>". "<xupdate:update select='/simple/fxp'>TITI</xupdate:update></xupdate:modifications>"; $db->xupdateResource('/db/test.xml', $xupdate); */ $db->disconnect() or die ($db->getError()); } catch( Exception $e ) { die($e); } ?>
use eXist::DB; my $eXist = new eXist::DB(); # USER => "guest", # PASSWD => "guest", # WSDL => "http://localhost/exist/services/Query?WSDL"); my $session = $eXist->connect("guest", "guest"); $query = <<END; for \$speech in //SPEECH[LINE &= 'love'] return \$speech END my %result = $eXist->xquery($session, $query); my $hits = $result{HITS}; my $queryTime = $result{QUERY_TIME}; my @collections = $result{COLLECTIONS}; print "found $hits hits in $queryTime ms.\n"; foreach $xml (@{$result{XML}}) { print $xml . "\n"; } $eXist->disconnect();
Òscar Celma
oscar.celma (at iua dot upf dot edu)