Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: XML::LibXML and namespaces

by choroba (Chancellor)
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]
[shmem]: ctags is a program which (recursively) extracts the symbols from source and stores them in a one-file database. This allows you to query the locations where these symbols (e.g. a subroutine name) are used anywhere in the source code tree...
[shmem]: ...from inside the editor.
[shmem]: apt-get install exuberant-ctags
[Lady_Aleena]: I think I heard vim has a big learning curve.
[shmem]: then in the root of your source tree run: ctags -R
[shmem]: you get a file named tags where all symbols and the places where they are used are listed
[Lady_Aleena]: geany may not support that.
[shmem]: I see that there is a plugin geany-plugin- codenav
[shmem]: maybe that supports ctags, check the documentation

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-04-27 12:11 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (506 votes). Check out past polls.