# ---------------------------------------------------------
# Lizenz: GPL                                              
# (c) Martin Raspe, Bibliotheca Hertziana, 2004            
# ---------------------------------------------------------
# additional convenience subs for XML::LibXML::SAX::Builder


# --------------------
package XML::LibXML::SAX::Builder;
# --------------------

use strict;

my ($opt);

# -------------------------
sub toString {
# -------------------------
my ($self) = @_;
my $dom = $self->result();
print $dom->toString(1);
# $self->done();
}

# -------------------------
sub toFile {
# -------------------------
my ($self, $xmlname) = @_;
return $self->toString() unless $xmlname;
print "Saving '$xmlname'\n";
my $dom = $self->result();
$dom->toFile($xmlname, 1);
# $self->done();
}

# -------------------------
sub toExist {
# -------------------------
my ($self, $url, $collection, $xmlname) = @_;
my $dom = $self->result();
my $xml = $dom->toString(1);
$self->done();
require RPC::XML;
require RPC::XML::Client;
print "Connecting to $url ... ";
my $client = RPC::XML::Client->new($url);
die( "no connection!\n" ) unless $client;
print "ok.\nStoring '$xmlname' in collection '$collection' ... ";
my $req = RPC::XML::request->new(
	"parse", 
	RPC::XML::base64->new($xml),
	RPC::XML::string->new("$collection/$xmlname"),
	RPC::XML::int->new(1),
	);
my $response = $client->send_request($req);
if ($response->is_fault()) {
	print( "error!\n". $response->string . "\n")
	}
else { print( "ok.\n") };
return $response->value();
}

__FILE__
