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~520 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=e6bfba4ec8171872285ef6a8d077700cd871b6da;p=irspy-moved-to-github.git 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});