X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=lib%2FZOOM%2FIRSpy%2FRecord.pm;h=c213f54a3655add5c9742f51f389d0c683e406ec;hb=1c2598aeac397399e015f5c1a83ab036a98e3938;hp=081e19d064f4db4971263ad3817806109be76101;hpb=d279b72e4e1af82605815866f0f52a40328531bf;p=irspy-moved-to-github.git diff --git a/lib/ZOOM/IRSpy/Record.pm b/lib/ZOOM/IRSpy/Record.pm index 081e19d..c213f54 100644 --- a/lib/ZOOM/IRSpy/Record.pm +++ b/lib/ZOOM/IRSpy/Record.pm @@ -1,4 +1,4 @@ -# $Id: Record.pm,v 1.11 2006-09-25 12:39:34 mike Exp $ +# $Id: Record.pm,v 1.15 2006-10-13 13:41:57 sondberg Exp $ package ZOOM::IRSpy::Record; @@ -6,6 +6,9 @@ use 5.008; use strict; use warnings; +use Exporter 'import'; +our @EXPORT_OK = qw(xml_encode); + use XML::LibXML; use XML::LibXML::XPathContext; @@ -26,7 +29,7 @@ I<## To follow> sub new { my $class = shift(); - my($target, $zeerex) = @_; + my($irspy, $target, $zeerex) = @_; if (!defined $zeerex) { $zeerex = _empty_zeerex_record($target); @@ -34,6 +37,7 @@ sub new { my $parser = new XML::LibXML(); return bless { + irspy => $irspy, target => $target, parser => $parser, zeerex => $parser->parse_string($zeerex)->documentElement(), @@ -86,7 +90,7 @@ sub append_entry { my $root = $this->{zeerex}; # XML::LibXML::Element ISA XML::LibXML::Node my $xc = XML::LibXML::XPathContext->new($root); $xc->registerNs(zeerex => "http://explain.z3950.org/dtd/2.0/"); - $xc->registerNs(irspy => "http://indexdata.com/irspy/1.0"); + $xc->registerNs(irspy => $ZOOM::IRSpy::irspy_ns); my @nodes = $xc->findnodes($xpath); if (@nodes == 0) { @@ -101,8 +105,8 @@ sub append_entry { if @nodes == 0; } - ZOOM::Log::log("irspy", - scalar(@nodes), " matches for '$xpath': using first") + $this->{irspy}->log("warn", + scalar(@nodes), " matches for '$xpath': using first") if @nodes > 1; $this->_half_decent_appendWellBalancedChunk($nodes[0], $frag); @@ -125,7 +129,7 @@ sub append_entry { # namespace mapping for that node -- but that only affects pre-parsed # trees, and is no use for parsing. Hence the following pair of lines # DOES NOT WORK: -# $node->setNamespace("http://indexdata.com/irspy/1.0", "irspy", 0); +# $node->setNamespace($ZOOM::IRSpy::irspy_ns, "irspy", 0); # $node->appendWellBalancedChunk($frag); # # Instead I have to go the long way round, hence this method. I have @@ -139,7 +143,7 @@ sub _half_decent_appendWellBalancedChunk { my($node, $frag) = @_; if (1) { - $frag =~ s,>, xmlns:irspy="http://indexdata.com/irspy/1.0">,; + $frag =~ s,>, xmlns:irspy="$ZOOM::IRSpy::irspy_ns">,; $node->appendWellBalancedChunk($frag); return; }