Your skill will accomplish
what the force of many cannot
XML::LibXML and namespacesby Anonymous Monk
|on Nov 09, 2012 at 09:29 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
I have a bunch of XML files from my GPS, and I'd like to extract data from them, and play around with them, displaying them graphically for one. As it's done properly, it has its own schema, and uses its own namespace. One such file can be found at www.dehulst.nl/Garmin/TCX/1832.tcx
So, in order to parse such an XML file, you have to register it with XML::LibXML (using a variable $string as the prefix)
Now, extracting the value of an attribute poses no problem:
Just in case anyone is worried, there (usually) is only one Lap per file.
The problems start when I want to extract the timestamps from each recorded datapoint. My first try was
This fails. It does find the set of nodes, but fails to find the timestamp that's in the Time element. Experimenting with the examples I Googled, I found the following, which does give me the timestamps:
That's nasty. It does work, but it's nasty.
So, the question is: why does the findvalue function fail to work with a non-default namespace? Or am I missing something?