[XML-SIG] element-value in multiple namespace

Stefan Behnel stefan_ml at behnel.de
Sun Nov 30 21:24:53 CET 2008


Hi,

Christian Benke wrote:
> I'm currently struggling to extract some information from a gpx-file
> (geodata in xml-format). You can see the xml-content here:
> http://benko.login.cx/2008-11-21.xml
> 
> So far i've managed to get out most of the values with this function:
> 
> tree = etree.parse(gpxfile)
>     gpx_namespace = "http://www.topografix.com/GPX/1/1"
>     root = tree.getroot()
>     trackSegments = root.getiterator("{%s}trkseg"%gpx_namespace)
>     for trackSegment in trackSegments:
>         for trackPoint in trackSegment:
>             lat=trackPoint.attrib['lat']
>             lon=trackPoint.attrib['lon']
>             altitude=trackPoint.find('{%s}ele'% gpx_namespace).text
>             time=trackPoint.find('{%s}time'% gpx_namespace).text
> 
> However, i have little idea what the syntax to pick out the
> values of the Temperature- and Pressure-elements has to be, which have
> an additional namespace

Then use that namespace to ask for them in exactly the same way as you did
above with the gpx_namespace.

http://effbot.org/zone/element-namespaces.htm
http://effbot.org/zone/element-xpath.htm


> plus they have a "gpxx:"-prefix.

Prefixes are not relevant. What counts is the namespace URI.

Stefan



More information about the XML-SIG mailing list