mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-30 23:30:04 +00:00
support all xml namespaces
This commit is contained in:
@@ -2,11 +2,29 @@ import { XMLParser, XMLBuilder } from "fast-xml-parser";
|
||||
import { GPXFileType } from "./types";
|
||||
import { GPXFile } from "./gpx";
|
||||
|
||||
const attributesWithNamespace = {
|
||||
'RoutePointExtension': 'gpxx:RoutePointExtension',
|
||||
'rpt': 'gpxx:rpt',
|
||||
'TrackPointExtension': 'gpxtpx:TrackPointExtension',
|
||||
'PowerExtension': 'gpxpx:PowerExtension',
|
||||
'atemp': 'gpxtpx:atemp',
|
||||
'hr': 'gpxtpx:hr',
|
||||
'cad': 'gpxtpx:cad',
|
||||
'Extensions': 'gpxtpx:Extensions',
|
||||
'PowerInWatts': 'gpxpx:PowerInWatts',
|
||||
'power': 'gpxpx:PowerExtension',
|
||||
'line': 'gpx_style:line',
|
||||
'color': 'gpx_style:color',
|
||||
'opacity': 'gpx_style:opacity',
|
||||
'width': 'gpx_style:width',
|
||||
};
|
||||
|
||||
export function parseGPX(gpxData: string): GPXFile {
|
||||
const parser = new XMLParser({
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: "",
|
||||
attributesGroupName: 'attributes',
|
||||
removeNSPrefix: true,
|
||||
isArray(name: string) {
|
||||
return name === 'trk' || name === 'trkseg' || name === 'trkpt' || name === 'wpt' || name === 'rte' || name === 'rtept' || name === 'gpxx:rpt';
|
||||
},
|
||||
@@ -17,22 +35,8 @@ export function parseGPX(gpxData: string): GPXFile {
|
||||
return attrValue;
|
||||
},
|
||||
transformTagName(tagName: string) {
|
||||
if (tagName === 'power') {
|
||||
// Transform the simple <power> tag to the more complex <gpxpx:PowerExtension> tag, the nested <gpxpx:PowerInWatts> tag is then handled by the tagValueProcessor
|
||||
return 'gpxpx:PowerExtension';
|
||||
}
|
||||
// Add the gpx_style namespace to the line style tags
|
||||
if (tagName === 'line') {
|
||||
return 'gpx_style:line';
|
||||
}
|
||||
if (tagName === 'color') {
|
||||
return 'gpx_style:color';
|
||||
}
|
||||
if (tagName === 'opacity') {
|
||||
return 'gpx_style:opacity';
|
||||
}
|
||||
if (tagName === 'width') {
|
||||
return 'gpx_style:width';
|
||||
if (attributesWithNamespace[tagName]) {
|
||||
return attributesWithNamespace[tagName];
|
||||
}
|
||||
return tagName;
|
||||
},
|
||||
|
Reference in New Issue
Block a user