in reply to XML::LibXML with namespace with no prefix
You can write xpaths like this
my $firstWeightXpath = qq{ //*:data[ attribute:key="$weightKey" ] [0] };
I use this helper , allows you to use it on dom and nodes, like
$dom->F( '//what:ever', 'what' => 'urn:yeahwhatever', 'that' => 'urn:thatalso', )->[0]->F('//what:else/that:there'); 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 ); }
Example of usage at Re^2: XML namespace question
I also use xpather.pl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML::LibXML with namespace with no prefix
by dallen16 (Sexton) on Dec 04, 2015 at 01:13 UTC | |
by Anonymous Monk on Dec 04, 2015 at 01:30 UTC |