python 3.x xml parsing similar to plistlib?

fafattaspData

New Member
I have GPS data stored as as .tcx file.This is a xml file (begging of file below)\[code\]<?xml version="1.0" encoding="utf-8"?><TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tp1="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpx="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd"> <Activities> <Activity Sport="Other"> <Id>2012-01-17T11:44:35Z</Id> <Lap StartTime="2012-01-17T11:44:35Z"> <TotalTimeSeconds>0</TotalTimeSeconds> <DistanceMeters>0</DistanceMeters> <Calories>0</Calories> <Intensity>Active</Intensity> <TriggerMethod>Manual</TriggerMethod> <Track> <Trackpoint> <Time>2012-01-17T11:44:35Z</Time> <Position> <LatitudeDegrees>59.720211518183351</LatitudeDegrees>\[/code\]The only similar thing I have worked with have been apple .plists which use a similar format, although the info is nested within a \[code\]<dictionary>\[/code\] tag I believe. Where the following would give me nested dictionaries...\[code\]import plistlibpl = plistlib.readPlist('/Users/name/Documents/file.plist')for sub_dict in pl: print(sub_dict['keyA']) print(sub_dict['keyD']) print(sub_dict['keyE']) print(sub_dict['keyG'])\[/code\]I am aware of xml.dom.minidom, etree and lxml, but I am having trouble working out how to get the same output as the above plistlib module gives me.My final aim is to be able to merge selected keys from the two data sets together. One step at a time... EDIT -----------------I have got something working:\[code\]from xml.dom.minidom import parsedoc = parse('/Users/name/Documents/GPS/gps.tcx')lat = doc.getElementsByTagName("LatitudeDegrees")time = doc.getElementsByTagName("Time")for x in lat: print(x.firstChild.data)\[/code\]
 
Top