perl - XML::LibXML: doc - root -


is here call of documentelemtent in first example superfluous?

#!/usr/bin/env perl use warnings; use strict; use xml::libxml; 

my $file = 'xml_file';  $doc = xml::libxml->load_xml( location => $file ); $root = $doc->documentelement(); $xpc = xml::libxml::xpathcontext->new( $root ); # ... $_->nodename $xpc->findnodes( '/' ); 

outputs

#document 

$doc = xml::libxml->load_xml( location => $file ); $xpc = xml::libxml::xpathcontext->new( $doc ); # ... $_->nodename $xpc->findnodes( '/' ); 

outputs also

#document 

any prefixes defined in topic node adopted xpc, 2 different if there prefixes defined on root node.

use warnings; use strict; use feature qw( );  use xml::libxml qw( );  $xml = <<'__eoi__'; <root xmlns:foo="uri:xxx"> <foo:bar/> </root> __eoi__  $doc  = xml::libxml->load_xml( string => $xml ); $root = $doc->documentelement();  {    $xpc = xml::libxml::xpathcontext->new($doc);    "doc:";    $_->nodename $xpc->findnodes('foo:bar'); }  "";  {    $xpc  = xml::libxml::xpathcontext->new($root);    "root:";    $_->nodename $xpc->findnodes('foo:bar'); } 

doc:  root: foo:bar 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -