Jun 2, 10:59 PM by Steve | Fixing Corrupted Garmin TCX Files

Posted in &

I guess I’ve been getting a bit of reputation as a magical fixer of corrupted TCX files. If this doesn’t mean anything to you, then don’t worry. This is all because the new firmware for the Garmin Edge 705 is not writing it’s data files correctly in some circumstances. Fortunately the nature of the TCX file format makes the bad files easy to fix if you understand XML. Unfortunately although it is possible to make the files readable again, there is usually some (or a lot) of data lost.

I can’t really explain XML here but the basic idea is that it consists of nodes enclosed in pairs of opening and closing tags. Every opening tag must have a matching closing tag. Every data sample in the file is a node called a trackpoint. For example:

<Trackpoint> <Time>2009-05-31T14:57:58Z</Time> <Position><LatitudeDegrees>42.290926</LatitudeDegrees><LongitudeDegrees>-71.389760</LongitudeDegrees></Position> <AltitudeMeters>61.804</AltitudeMeters> <DistanceMeters>92.244</DistanceMeters> <HeartRateBpm><Value>94</Value></HeartRateBpm> <Cadence>4</Cadence> <SensorState>Present</SensorState> <Extensions><TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2"><Watts>26</Watts></TPX></Extensions> </Trackpoint>

So the basic building block of the TCX file is the Trackpoint, but there is a hierarchy to the file. One or more Trackpoint nodes are enclosed in a Track node and, one or more Track nodes make up a Lap node. A new track is created whenever the unit auto-pauses. Finally, at the top level, an Activity node contains one or more Lap nodes. There is only one Activity per file.

When the corruption happens, there is typically a trackpoint that has failed to write correctly and then the rest of the track is missing until the next track or lap starts. Because there is no matching closing trackpoint, track, and/or lap tags, the file is invalid and cannot be read by most programs. The “fix” is to remove the incomplete trackpoint and close out the track and/or lap. There is usually only one error like this but I’ve seen a few files that have more than one.

The first step to actually fix the file is to open the file in an editor. You can just open it in Notepad as it is a text file, but it will be difficult to find the bad nodes. I’ve found First Object XML Editor to work very well for our purposes, and it’s free to boot. This editor is nice because it can still parse the file and display the heirarchy even with the bad nodes, and as a bonus it highlights the bad nodes so they are really easy to find. With the file open, expand the nodes until you find one that is colored yellow, such as the Track node pictured here. This node is beginning of the problem as it does not have a closing tag, but it is not the end of the problem. Do not simply delete this node in the tree, it will not fix the corruption!

The real problem here is the lack of the closing tag, so scroll down the tree until you see a Trackpoint that is colored yellow, and the start of the next Track. If you double click on the last item before the next good Track it will highlight it in the text on the right.

Delete everything from after the last closed Trackpoint to before the start of the next Track, and replace with a closing Track tag as pictured below. Note that if it is the last Track in a Lap you may also need to close the Lap. Save the file and refresh and the tree should collapse and display nicely. There may be more errors so repeat the process.

So those are the basics for fixing TCX files. Some errors are a little harder to find because of their location but the principles are the same. If you have a file that you cannot fix feel free to send it to me, but please zip it first.

Kim & Steve>Fixing Corrupted Garmin TCX Files | | | About | Gallery | Feed
© 2004-2010 by Kimberly & Steven Weixel | Hosted by Pair | Powered by Textpattern 4.2.0 | Log in