#!/usr/local/bin/perl

use strict;
use warnings;

use Sleepycat::DbXml 'simple' ;

#
# Example 4
#
# Create an XML Container, define an equality string index
# for booktitle elements, add a document, query the container
# for the document, iterate over the result set displaying
# the values returned.
#
# Note that this example assumes that the 'test' container
# does not already exist. If it does exist then the
# declareIndex method will throw an exception to complain
# that the container isn't empty.
#

eval
{
	my $container = new XmlContainer("test.dbxml");
	$container->open(Db::DB_CREATE);
	$container->addIndex("","title","node-element-equality-string");
	my $document = new XmlDocument ;
	my $content ="<book><title>Knowledge Discovery in Databases.</title></book>";
	$document->setContent($content);
	$container->putDocument($document);
	my $results = $container->queryWithXPath("//*[title='Knowledge Discovery in Databases.']");
	my $value = new XmlValue ;
	while ($results->next($value))
	{
		my $document = $value->asDocument();
		print $document->getID() . " = " . $value->asString . "\n";
	}
	$container->close();
	$container->remove();
};

if (my $e = catch std::exception)
{
	warn $e->what() . "\n";
}
elsif ($@)
{
	warn $@;
}

