mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +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 { GPXFileType } from "./types";
|
||||||
import { GPXFile } from "./gpx";
|
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 {
|
export function parseGPX(gpxData: string): GPXFile {
|
||||||
const parser = new XMLParser({
|
const parser = new XMLParser({
|
||||||
ignoreAttributes: false,
|
ignoreAttributes: false,
|
||||||
attributeNamePrefix: "",
|
attributeNamePrefix: "",
|
||||||
attributesGroupName: 'attributes',
|
attributesGroupName: 'attributes',
|
||||||
|
removeNSPrefix: true,
|
||||||
isArray(name: string) {
|
isArray(name: string) {
|
||||||
return name === 'trk' || name === 'trkseg' || name === 'trkpt' || name === 'wpt' || name === 'rte' || name === 'rtept' || name === 'gpxx:rpt';
|
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;
|
return attrValue;
|
||||||
},
|
},
|
||||||
transformTagName(tagName: string) {
|
transformTagName(tagName: string) {
|
||||||
if (tagName === 'power') {
|
if (attributesWithNamespace[tagName]) {
|
||||||
// Transform the simple <power> tag to the more complex <gpxpx:PowerExtension> tag, the nested <gpxpx:PowerInWatts> tag is then handled by the tagValueProcessor
|
return attributesWithNamespace[tagName];
|
||||||
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';
|
|
||||||
}
|
}
|
||||||
return tagName;
|
return tagName;
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user