in reply to Re: XML namespace question
in thread XML namespace question

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use XML::LibXML 1.70; ## for load_html/load_xml/location sub XML::LibXML::Node::F { my $self = shift; my $xpath = shift; my %prefix = @_; our $XPATHCONTEXT; $XPATHCONTEXT ||= XML::LibXML::XPathContext->new(); while( my( $p, $u ) = each %prefix ){ $XPATHCONTEXT->registerNs( $p, $u ); } $XPATHCONTEXT->findnodes( $xpath, $self ); } my $doc = XML::LibXML->new()->parse_string(q{<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/12.3R9/junos"> <vlan-information junos:style="terse"> <vlan-terse/> <vlan> ... </vlan> </vlan-information> </rpc-reply> }); ## "registration" find a node that don't exist $doc->F( "/NOTExIST", 'nc', 'urn:ietf:params:xml:ns:netconf:base:1.0', 'j', 'http://xml.juniper.net/junos/12.3R9/junos', ); for my $vlaninfo( $doc->F( "/nc:rpc-reply/nc:vlan-information", ) ){ my( $style ) = $vlaninfo->F('./@j:style'); print "$style\n"; dd( { %$vlaninfo }); } __END__ junos:style="terse" { "{http://xml.juniper.net/junos/12.3R9/junos}style" => "terse" }