#!/usr/local/bin/perl

use strict;
use warnings;

use Sleepycat::DbXml 'simple';

#
# Example 7
#
# Create an XML Container within a Berkeley DB environment,
# add a document, get the document, display the content of
# the document.
#

eval
{
	my $dbenv = new DbEnv;
	$dbenv->open(undef, Db::DB_CREATE | Db::DB_INIT_MPOOL);
	my $container = new XmlContainer($dbenv, "test.dbxml");
	$container->open(Db::DB_CREATE);
	my $document = new XmlDocument ;
	$document->setContent("<book><title>Knowledge Discovery in Databases.</title></book>");
	my $id = $container->putDocument($document);
	$document = $container->getDocument($id);
	print "$id = " . $document->getContentAsString . "\n";
	$container->close();
	$container->remove();
	$dbenv->close();
};

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