I am using the .NET XmlSerializer class to deserialize GPX files.
There are two versions of the GPX standard:
- <gpx xmlns=”http://www.topografix.com/GPX/1/0″> … </gpx>
- <gpx xmlns=”http://www.topografix.com/GPX/1/1″> … </gpx>
Also, some GPX files do not specify a default namespace:
- <gpx> … </gpx>
My code needs to handle all three cases, but I can’t work out how to get XmlSerializer to do it.
I am sure there must be a simple solution because this a common scenario, for example KML has the same issue.
Here’s the solution I came up with before the other suggestions came through:
This example accepts any namespace, but you could easily make it filter for a specific list of known namespaces.