Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of xsi:schemaLocation cannot be appended #210

Open
ekspla opened this issue Oct 19, 2020 · 2 comments
Open

List of xsi:schemaLocation cannot be appended #210

ekspla opened this issue Oct 19, 2020 · 2 comments

Comments

@ekspla
Copy link
Contributor

ekspla commented Oct 19, 2020

I am very new to gpxpy and want to have a gpx file similar to those from Garmin. The xsi:schemaLocation should be looked like this:

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"

The following script generates the first two of the above mentioned schemaLocation.

gpx = gpxpy.gpx.GPX()
gpx_track = gpxpy.gpx.GPXTrack()
gpx.tracks.append(gpx_track)
gpx.nsmap["gpxtpx"] = "http://www.garmin.com/xmlschemas/TrackPointExtension/v1"
gpx.nsmap["gpxx"] = "http://www.garmin.com/xmlschemas/GpxExtensions/v3"
print(gpx.to_xml('1.1'))

However, appending the rest to the list of schema_locations fails. It generates only the list of the added four.

gpx.schema_locations += ['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']

Is this an intentional behaviour that the list cannot be appended?
We can, of course, write the complete list like this.

gpx.schema_locations = ['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']

I am using Python 3.6 and gpxpy 1.4.2.

@ekspla
Copy link
Contributor Author

ekspla commented Oct 21, 2020

I found that the default list of xsi:schemaLocation is generated after calling gpx.to_xml(). That is why the list can neither be appended nor extended before the call.

@ekspla
Copy link
Contributor Author

ekspla commented Oct 22, 2020

I think it would be nice to check if schema_locations of topografix are given when 'to_xml()' is called.

For example, in the code of def to_xml() in gpx.py (lines from 2698, version 1.4.2):

        default_schema_locations = [
            p.format(version_path) for p in (
                'http://www.topografix.com/GPX/{0}',
                'http://www.topografix.com/GPX/{0}/gpx.xsd',
            )
        ]
        if not set(self.schema_locations) >= set(default_schema_locations):
            self.schema_locations = default_schema_locations + self.schema_locations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant