[Xml-compile] Beginner's question: Using XML::eXistDB::RPC with XQuery

Mirco Hilbert Mirco.Hilbert at germanistik.uni-giessen.de
Thu Jun 17 10:08:06 GMT 2010


Hello!

I started testing your Perl module XML::eXistDB sending XQuery requests to an eXist database on my local host.
I'm using the example Shakespeare database by exist-db.org and the following small Perl script:

> #!/usr/bin/perl -w
> use strict;
> 
> use XML::LibXML;
> use XML::eXistDB::RPC;
> use Data::Dumper;
> 
> my $existDB = XML::eXistDB::RPC->new(destination => 'http://localhost:8080/exist/xmlrpc',
>                                      user => 'guest', password => 'guest',
>                                      repository => '/db');
> 
> my $xquery = 'for $play in collection(\'/db/shakespeare/plays\')//PLAY
>               return <PLAY>{$play/TITLE, $play/SCNDESCR}</PLAY>';
> 
> my ($rc1, $set)   = $existDB->executeQuery($xquery);
> my ($rc2, $count) = $existDB->numberOfResults($set);
> my ($rc3, @data)  = $existDB->retrieveResults($set);
> $existDB->releaseResultSet($set);
> 
> print Dumper(@data);

The first message I run into is the following warning (but, apparently, I can ignore it):

> Prototype mismatch: sub XML::Compile::RPC::Client::trace (@) vs () at /usr/local/share/perl/5.10.0/XML/Compile/RPC/Client.pm line 54.
> Subroutine trace redefined at /usr/local/share/perl/5.10.0/XML/Compile/RPC/Client.pm line 54.

The result I get here in @data is a nested hash structure.

But I wonder if there is a possibility to get the result as an XML::LibXML::Document or XML::LibXML::Element object? Or maybe more intuitively as an array of XML::LibXML::Document or XML::LibXML::Element objects respectively, as the result of an XQuery request may also be a sequence?
Is there such a possibility which I maybe have overlooked reading the documentation? Maybe using the FORMAT parameter of retrieveResults?

I'm working with XML::LibXML and XML::LibXSLT to handle and process XML data, I searched for some kind of XML::LibXQuery with a similar ease of use as XML::LibXSLT. And the above usage of XML::eXistDB::RPC would fulfill this kind of task with the constraint dealing with eXist databases.

Best regards,

   Mirco

--
perl v5.10.0
XML::eXistDB v0.11
XML::Compile v1.15
XML::LibXML v1.70




More information about the Xml-compile mailing list