From: Mike Taylor Date: Fri, 16 Jun 2006 15:28:46 +0000 (+0000) Subject: WOrking version using XPathContext X-Git-Tag: CPAN-v1.02~54^2~1180 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=bbc101a9ff142bf4588be29f5a81acffb39a1c2b;p=irspy-moved-to-github.git WOrking version using XPathContext --- diff --git a/zebra/ezeerex2pqfproperties.pl b/zebra/ezeerex2pqfproperties.pl index c8b9485..09f6df4 100755 --- a/zebra/ezeerex2pqfproperties.pl +++ b/zebra/ezeerex2pqfproperties.pl @@ -1,25 +1,22 @@ #! /usr/bin/perl -w -# $Id: ezeerex2pqfproperties.pl,v 1.1 2006-06-05 09:18:58 mike Exp $ +# $Id: ezeerex2pqfproperties.pl,v 1.2 2006-06-16 15:28:46 mike Exp $ use strict; use warnings; use XML::LibXML; +use XML::LibXML::XPathContext; my $text = join("", <>); my $parser = new XML::LibXML(); my $doc = $parser->parse_string($text); my $root = $doc->getDocumentElement(); -print "root=$root, ISA=(", join(", ", @XML::LibXML::Element::ISA), ")\n"; -$root->registerDefaultNs("/.//") -my (@nodes) = $root->findnodes('serverInfo/host'); +my $xc = XML::LibXML::XPathContext->new($root); +$xc->registerNs(zeerex => "http://explain.z3950.org/dtd/2.0/"); +print "root=$root, xc=$xc\n"; +my(@nodes) = $xc->findnodes('zeerex:serverInfo/zeerex:host'); print "found ", scalar(@nodes), " values\n"; - -## From http://plasmasturm.org/log/259/ -#use XML::LibXML; -#use XML::LibXML::XPathContext; -#my $p = XML::LibXML->new(); -#my $doc = $p->parse_file( $ARGV[ 0 ] ); -#my $xc = XML::LibXML::XPathContext->new( $doc->documentElement() ); -#$xc->registerNs( atom => 'http://purl.org/atom/ns#' ); -#print $xc->findvalue( q{ /xsl:stylesheet/xsl:template[ @match = '/' ]/atom:feed/atom:link[ @rel = 'alternate' ]/@href } ); +for (my $i = 0; $i < @nodes; $i++) { + my $node = $nodes[$i]; + print $i+1, ": ", $node->toString(); +}