sibartlett / Geo

A geospatial library for .NET
https://www.nuget.org/packages/Geo/
GNU Lesser General Public License v3.0
176 stars 39 forks source link

Cannot read GPX files with missing namespace #55

Open tipa opened 2 years ago

tipa commented 2 years ago

I am using Gpx10Serializer and Gpx11Serializer in my app and want to deserialize GPX files from a stream. I have come across GPX files that do not have the correct namespace set:

<?xml version="1.0" encoding="UTF-8"?>
<gpx creator="Runtastic: Life is short - live long, http://www.runtastic.com" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"><metadata><name>runtastic_20220225_0813</name>
<copyright author="www.runtastic.com"><year>2022</year>
<license>http://www.runtastic.com</license>
</copyright>
<link href="http://www.runtastic.com"><text>runtastic</text>
</link>
...
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0" creator="GeoSetter - http://www.geosetter.de">
<trk>
<name></name>
<trkseg>
...

This causes the deserialization to fail with an InvalidOperationException (<gpx xmlns=''> was not expected) because of this attribute (I think): https://github.com/sibartlett/Geo/blob/44fdae6c62bf46681685f9ed6d775d3c78dbeebe/Geo/Gps/Serialization/Xml/Gpx/Gpx11/GpxFile.cs#L6 https://github.com/sibartlett/Geo/blob/44fdae6c62bf46681685f9ed6d775d3c78dbeebe/Geo/Gps/Serialization/Xml/Gpx/Gpx10/GpxFile.cs#L6

It would be great if it was possible to ignore that namespace so that the library can also import those GPX files