PHP and Perl Classes for eXist XML database


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.

Detailed description

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


2007-04-05 : Version 0.5

	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

Programming Languages


PHP4 (deprecated):

Perl (deprecated):

Code examples

Example in PHP5:

  include ('include/eXist.php');
  # (1) XQuery example
        $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
        $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 )
  # (2) Adding/removing documents and collections
  	$db = new eXistAdmin('guest', 'guest', '');
	$db->connect() or die ($db->getError());

	// Store Document
				'/db/test.xml', true);
				'/db/test2suppr.xml', true);
	// Remove Document

	// Create collection
	// Remove collection

	// 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 )


Example in Perl (not tested since...ages!):

  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

  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";



GNU General Public License (GPL)


Òscar Celma


oscar.celma (at iua dot upf dot edu)