X-Git-Url: http://git.indexdata.com/?p=irspy-moved-to-github.git;a=blobdiff_plain;f=lib%2FZOOM%2FIRSpy%2FRecord.pm;h=081e19d064f4db4971263ad3817806109be76101;hp=2f67dc1d2b60e5eba2a58ac097c761b02025b713;hb=69dac006c8683ba1b15afd8208004f439af5a1a1;hpb=391c3c432affeb3fd322e6131dcce29a71fe6bb5 diff --git a/lib/ZOOM/IRSpy/Record.pm b/lib/ZOOM/IRSpy/Record.pm index 2f67dc1..081e19d 100644 --- a/lib/ZOOM/IRSpy/Record.pm +++ b/lib/ZOOM/IRSpy/Record.pm @@ -1,4 +1,4 @@ -# $Id: Record.pm,v 1.8 2006-07-24 16:44:00 mike Exp $ +# $Id: Record.pm,v 1.11 2006-09-25 12:39:34 mike Exp $ package ZOOM::IRSpy::Record; @@ -47,23 +47,42 @@ sub _empty_zeerex_record { ### Doesn't recognise SRU/SRW URLs my($host, $port, $db) = ZOOM::IRSpy::_parse_target_string($target); + my $xhost = xml_encode($host); + my $xport = xml_encode($port); + my $xdb = xml_encode($db); return <<__EOT__; - $host - $port - $db + $xhost + $xport + $xdb __EOT__ } +# I can't -- just can't, can't, can't -- believe that this function +# isn't provided by one of the core XML modules. But the evidence all +# says that it's not: among other things, XML::Generator and +# Template::Plugin both roll their own. So I will do likewise. D'oh! +# +sub xml_encode { + my ($text) = @_; + $text =~ s/&/&/g; + $text =~ s//>/g; + $text =~ s/['']/'/g; + $text =~ s/[""]/"/g; + return $text; +} + + sub append_entry { my $this = shift(); my($xpath, $frag) = @_; - print STDERR "this=$this, xpath='$xpath', frag='$frag'\n"; + #print STDERR "this=$this, xpath='$xpath', frag='$frag'\n"; 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/"); @@ -86,10 +105,7 @@ sub append_entry { scalar(@nodes), " matches for '$xpath': using first") if @nodes > 1; - my $node = $nodes[0]; - # $node ISA XML::LibXML::ElementXML::LibXML::Element - $this->_half_decent_appendWellBalancedChunk($node, $frag); - #print STDERR "POST: zeerex='$root' = \n", $root->toString(), "\n"; + $this->_half_decent_appendWellBalancedChunk($nodes[0], $frag); } @@ -140,7 +156,7 @@ sub _half_decent_appendWellBalancedChunk { die "mismatched XML start/end <$open>...<$close>" if $close ne $tag; print STDERR "tag='$tag', attrs=[$attrs], content='$content'\n"; - die "### no code yet to make DOM node"; + die "## no code yet to make DOM node"; }