From: Mike Taylor Date: Mon, 19 Mar 2007 18:51:03 +0000 (+0000) Subject: irspy_xpath_context() can now take a LibXML element as well as a X-Git-Tag: CPAN-v1.02~54^2~465 X-Git-Url: http://git.indexdata.com/?p=irspy-moved-to-github.git;a=commitdiff_plain;h=5cc7c7423877cc60242402f6a33553d5447d8457 irspy_xpath_context() can now take a LibXML element as well as a ZOOM::Record and a textual XML document. --- diff --git a/lib/ZOOM/IRSpy/Utils.pm b/lib/ZOOM/IRSpy/Utils.pm index 5942108..5db0e33 100644 --- a/lib/ZOOM/IRSpy/Utils.pm +++ b/lib/ZOOM/IRSpy/Utils.pm @@ -1,4 +1,4 @@ -# $Id: Utils.pm,v 1.25 2007-03-05 19:41:57 mike Exp $ +# $Id: Utils.pm,v 1.26 2007-03-19 18:51:03 mike Exp $ package ZOOM::IRSpy::Utils; @@ -106,10 +106,19 @@ sub irspy_namespace { sub irspy_xpath_context { my($record) = @_; - my $xml = ref $record ? $record->render() : $record; - my $parser = new XML::LibXML(); - my $doc = $parser->parse_string($xml); - my $root = $doc->getDocumentElement(); + if (ref $record && $record->isa("ZOOM::Record")) { + $record = $record->render(); + } + + my $root; + if (ref $record) { + $root = $record; + } else { + my $parser = new XML::LibXML(); + my $doc = $parser->parse_string($record); + $root = $doc->getDocumentElement(); + } + my $xc = XML::LibXML::XPathContext->new($root); foreach my $prefix (keys %_namespaces) { $xc->registerNs($prefix, $_namespaces{$prefix});