Fix/gpx export chrome (#131)

* fix duplicate xmlns attribute for Chrome-based browsers but add it back in for Firefox

* remove log statement; improve comment

* derive xml namespace from defaultAttributes
This commit is contained in:
tofublock
2024-12-02 16:38:48 +01:00
committed by GitHub
parent b0abb52ce8
commit abe7ffbed7

View File

@@ -8,7 +8,7 @@ import Waypoint from './waypoint';
const defaultAttributes = {
version: '1.1',
creator: 'wanderer',
'xmlns:prod': 'http://www.topografix.com/GPX/1/1',
xmlns: 'http://www.topografix.com/GPX/1/1',
'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'
@@ -18,7 +18,7 @@ export default class GPX {
$: {
version: string;
creator: string;
'xmlns:prod': string;
xmlns: string;
'xmlns:xsi': string;
'xsi:schemaLocation': string;
}
@@ -32,7 +32,7 @@ export default class GPX {
$?: {
version: string,
creator: string,
'xmlns:prod': string,
xmlns: string,
'xmlns:xsi': string,
'xsi:schemaLocation': string,
}
@@ -151,6 +151,13 @@ export default class GPX {
const gpx = new GPX(this);
allDatesToISOString(gpx);
return builder.buildObject(gpx).replace('xmlns:prod', 'xmlns');
let xmlString = builder.buildObject(gpx);
// Ensure xmlns is present in the root element for Firefox
if (!xmlString.includes(`xmlns="${defaultAttributes["xmlns"]}"`)) {
xmlString = xmlString.replace('<gpx', `<gpx xmlns="${defaultAttributes["xmlns"]}"`);
}
return xmlString;
}
}