Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: XML::LibXML and namespaces

by Anonymous Monk
on Nov 09, 2012 at 11:30 UTC ( #1003102=note: print w/replies, xml ) Need Help??

in reply to XML::LibXML and namespaces

libxml can be quite a PITAPITCT - Pain In The Carpal Tunnel :)

#!/usr/bin/perl -- use strict; use warnings; use XML::LibXML; my $doc = XML::LibXML->new()->parse_string( q{<?xml version='1.0' ?> <roshambo xmlns=""> <sham> <bo name="40" /> <bo name="2" /> </sham> <sham> <bo name="forty" /> <bo name="two" /> </sham> </roshambo> } ); for my $node ( $doc->F( '//x:sham' ) ) { print "@{[ $node->nodePath ]}\n"; for my $name ( $node->F( 'x:bo/@name' ) ) { print "@{[ $name->nodePath ]} @{[$name->nodeValue]}\n"; } print "\n\n"; } $::xpc->registerNs( 'y', '' ); print $doc->F('y:roshambo'); exit( 0 ); BEGIN { $::xpc = XML::LibXML::XPathContext->new( ); $::xpc->registerNs( 'x', '' ); sub XML::LibXML::Node::F { my( $self, $xpath, $context ) = @_; $::xpc->findnodes( $xpath, $context || $self ); } } __END__

Also if you're interested in a fancier nodePath, see XPATH DOM traverse html/xml

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003102]
[ambrus]: Now it has five people instead of three, some sort of call number ticket system where people wait a lot for their food to get ready (it's the same kinds of grilled meat and fish on the same equipment, it won't actually fry slower),
[ambrus]: it's slow as hell, and the food costs significantly more.
[ambrus]: We no longer eat there.
LanX Everybody quotes it, some people read it, and a few people go by it
[ambrus]: LanX: why would I read it? isn't it a book for managers? I don't want to be a manager.
[ambrus]: I don't quote it either.
[erix]: it's really a software book, albeit about experiences from the 60s-80s. People haven't changed all that much though.
[erix]: a software project book, is probably more exact
[ambrus]: Yes, but I'm not managing software teams either.
[ambrus]: I'm not only not a restaurant manager, but also not a software manager.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-09-22 13:55 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (264 votes). Check out past polls.