in reply to Libxml xpath queries involving more than one name space.
#!/usr/bin/perl -w use strict; use warnings; use XML::LibXML qw( ); use XML::LibXML::XPathContext qw( ); my $file = $ARGV[0]; my $parser = XML::LibXML->new(); my $dom = $parser->load_xml( location => $file ); my $root = $dom->getDocumentElement(); my $xpc = XML::LibXML::XPathContext->new($root); $xpc->registerNs(t => 'http://www.Borkbot.net/telcel/Bork'); $xpc->registerNs(c => 'http://www.Borkbot.com/content'); my @nodes = $xpc->findnodes('//t:mp3Resource/c:resourceFilename'); foreach my $node (@nodes) { print($node->to_literal, "\n"); }
Update: Tested. Had wrong namespace. Misused registerNs. Fixed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Libxml xpath queries involving more than one name space.
by Anonymous Monk on Mar 10, 2010 at 18:53 UTC |