Skip to content

Instantly share code, notes, and snippets.

@vkurup
Created February 2, 2017 02:40
Show Gist options
  • Save vkurup/6abcfa568be126c6dfe771e3ccb7d12f to your computer and use it in GitHub Desktop.
Save vkurup/6abcfa568be126c6dfe771e3ccb7d12f to your computer and use it in GitHub Desktop.
Showing how to get arbitrary nodes in XML
(tcx)vinod@cartman:~/dev/python-tcxparser(master) $ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tcxparser
>>> tcx = tcxparser.TCXParser('test.tcx')
>>> tcx.root
<Element {http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2}TrainingCenterDatabase at 0x7f97eb2689e0>
>>> namespace = 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2'
>>> tcx.root.findall('.//ns:Extensions', namespaces={'ns': namespace})
[<Element {http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2}Extensions at 0x7f97eb26f098>]
>>> tcx.root.findall('.//ns:Speed', namespaces={'ns': namespace})
[3.032999992370606]
>>> tcx.root.findall('.//ns:Watts', namespaces={'ns': namespace})
[125]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment