#!/usr/local/bin/perl

use strict ;
use warnings;

use Sleepycat::DbXml 'simple' ;

#
# Example 2
#
# Create an XML Container, add a document, query the container
# for the document, iterate over the result set displaying the
# values returned.
#

eval
{
	my $container = new XmlContainer("test.dbxml");
	$container->open(Db::DB_CREATE);
	my $document = new XmlDocument ;
	my $content = <<EOM;
	    <book>
	        <title>
		    Knowledge Discovery in Databases.
		</title>
	    </book>
EOM

	$document->setContent($content);
	$container->putDocument($document);
	my $results = $container->queryWithXPath("/book");
	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 $@;
}
