Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: XML namespace question

by Anonymous Monk
on Oct 13, 2015 at 23:48 UTC ( [id://1144785]=note: print w/replies, xml ) Need Help??


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" }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1144785]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-28 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found