Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: XML::LibXML and namespaces

by choroba (Bishop)
on Nov 09, 2012 at 09:51 UTC ( #1003092=note: print w/replies, xml ) Need Help??

in reply to XML::LibXML and namespaces

See the documentation of XML::LibXML::Node under findnodes. If you follow the advice given there, your XPath will work:
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $file = '1832.tcx'; my $parser = XML::LibXML->new->parse_file($file); my $xml = XML::LibXML::XPathContext->new; # No argum +ent here! $xml->registerNs('x', ' +ase/v2'); for my $key ($xml->findnodes('//x:Lap', $parser)) { # Provide +the $parser here. my $string = $key->findvalue('@StartTime'); # No $pars +er needed, since attributes are namespaceless. print "1\t$string\n"; } my @X; for my $node ($xml->findnodes('//x:Trackpoint', $parser)) { # Again, $ +parser as argument. my $time = $xml->findvalue('x:Time', $node); # Context +specified as argument. push @X, $time; } print "@X\n";

Update: comments.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: XML::LibXML and namespaces
by Anonymous Monk on Nov 09, 2012 at 10:09 UTC

    Ah! That's what I was missing. I did try to put a context in, but I tried $xml, not $node.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003092]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2018-01-22 01:25 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (230 votes). Check out past polls.