[160] This specification defines how to parse GPX files.
[9] A data set has
name ,
description ,
keywords ,
generator ,
timestamp ,
updated ,
author ,
license ,
minimum latitude ,
minimum longitude ,
maximum latitude ,
maximum longitude ,
and
time-zone offset ,
which are initially null
.
[19] A data set has
waypoints ,
routes ,
tracks ,
and
links ,
which are initially empty lists .
[26] A point has
name ,
description ,
timestamp ,
latitude ,
longitude ,
elevation ,
geoid height ,
magnetic variation ,
comment ,
source ,
symbol name ,
type ,
fix ,
number of satellites ,
hdop ,
vdop ,
age of DGPS data ,
DGPS ID ,
speed ,
accuracy ,
temperature ,
water temperature ,
depth ,
cadence ,
distance ,
to distance ,
heartrate ,
point role ,
power ,
and
road type ,
which are initially null
.
[189] A route has links , which is initially an empty
list .
[45] A route has
name ,
description ,
comment ,
source ,
type ,
and
number ,
which are initially null
.
[62] A route has points
and
links ,
which are initially empty
lists .
[72] A track has
name ,
description ,
comment ,
source ,
type ,
and
number ,
which are initially null
.
[73] A track has segments
and
links ,
which are initially empty
lists .
[74] A track segment has points , which is initially an empty
list .
[43] A person has
name
and
email ,
which are initially null
.
[207] A person has
links ,
which is initially an empty list .
[51] A license has
holder ,
year , and
URL ,
which are initially null
.
[202] A link has
URL ,
MIME type ,
and
text ,
which are initially null
.
[188]
A track is a valid timestamped route if all of the following
conditions are true:
[206] An implementation MUST
use an XML parser that implements XML5
to parse a GPX file.
It MUST NOT fetch and process external entities .
[159] An implementation MUST
use the steps to parse a GPX document to parse a Document
as
a GPX document.
[1] To parse a GPX document doc , run these steps:[2] Let element be doc 's document element .[4] If element is an element whose local name is gpx
:[6] Return the result of parsing a gpx
element element .[11] Otherwise:[12] Return null .
[10] To parse a gpx
element element , run these steps:[79] Let data set be a data set .[17] Let creator be element 's creator
attribute value .[59] If creator is not null
and is not the empty string :[71] Set data set 's generator to creator .[179] Let tzoffset be element 's tzoffset
attribute value in the GPX extension namespace .[182] If tzoffset is not null
and is not the empty string :[183] Let offset be the result of
parsing a time-zone offset string
tzoffset .[184] If offset is not nothing:[181] Set data set 's time-zone offset to offset .[14] For each element child in element 's children :[15] Switch by child 's local name :metadata
[29] For each element gc in child 's children :[20] Process gc with data set ,
using the following table:l local name f Field r Rule l name
f name r String l desc
f description r String l keywords
f keywords r String l link
f links r Link l author
f author r Person l copyright
f license r License [30] If gc 's local name is time
:[83] If gc 's namespace is http://www.topografix.com/GPX/gpx_modified/0/1
:[88] If data set 's updated is null
:[85] Let text be gc 's child text content .[86] Parse a global date and time string
text .[87] If a time is returned,
set data set 's updated to the time.[84] Otherwise:[89] If data set 's timestamp is null
:[90] Let text be gc 's child text content .[91] Parse a global date and time string
text .[92] If a time is returned,
set data set 's timestamp to the time.[40] If gc 's local name is bounds
:[97] If data set 's minimum latitude is null
:[98] Set data set 's minimum latitude be the result of applying the
rules for parsing a latitude value to gc 's minlat
attribute value.[99] If data set 's minimum longitude is null
:[100] Set data set 's minimum longitude be the result of applying the
rules for parsing a longitude value to gc 's minlon
attribute value.[101] If data set 's maximum latitude is null
:[102] Set data set 's maximum latitude be the result of applying the
rules for parsing a latitude value to gc 's maxlat
attribute value.[103] If data set 's maximum longitude is null
:[104] Set data set 's maximum longitude be the result of applying the
rules for parsing a longitude value to gc 's maxlon
attribute value.wpt
Append the result of parsing a point element child
to data set 's waypoints . rte
Append the result of parsing a route element child
to data set 's routes . trk
Append the result of parsing a track element child
to data set 's tracks . [115] Return data set .
[27] To parse a point element element , run these steps:[25] Let point be a point .[116] Set point 's latitude to the result of applying the
rules for parsing a latitude value to element 's lat
attribute value .[118] Set point 's longitude to the result of applying the
rules for parsing a latitude value to element 's lon
attribute value .[185] Let road be element 's road
attribute value in the GPX extension namespace .[186] If road is a valid road type string :[187] Set point 's road type to road .
[218]
Let role be element 's pointrole
attribute value in the GPX extension namespace . [219] If role is a valid point role string :[220] Set point 's point role to role .[21] Set to distance
be
element 's todistance
attribute value in the GPX extension namespace .[22] If
to distance is not null
:[32]
Let number be the result of applying the
rules for parsing floating-point number values to to distance .[31]
If number is a number greater than or equal to 0 :[33]
Set point 's to distance
to number .[18] For each element child in element 's children :[154] Process child with point ,
using the following table:l local name f Field r Rule l sat
f number of satellites r Non-negative number l dgpsid
f DGPS ID r Non-negative integer l ele
f elevation r Number l geoidheight
f geoid height r Number l hdop
f hdop r Number l vdop
f vdop r Number l pdop
f pdop r Number l ageofdgpsdata
f age of DGPS data r Number l speed
f speed r Number l magvar
f magnetic variation r Degree l time
f timestamp r Time l name
f name r String l desc
f description r String l cmt
f comment r String l src
f source r String l sym
f symbol name r String l type
f type r String l fix
f fix r String l link
f links r Link [141] If child 's local name is extensions
:[143] For each element gc in child 's children :[144] Process gc with point ,
using the following table:l local name f Field r Rule l cadence
f cadence r Number l distance
f distance r Number l hr
f heartrate r Number l heartrate
f heartrate r Number l power
f power r Number l temp
f temperature r Number l speed
f speed r Number l accuracy
f accuracy r Number [145] If gc 's local name is TrackPointExtension
:[146] For each element ggc in gc 's children :[147] Process ggc with point ,
using the following table:l local name f Field r Rule l atemp
f temperature r Number l wtemp
f water temperature r Number l depth
f depth r Number l hr
f heartrate r Number l cad
f cadence r Number [161] Return point .
[52] To parse a route element element , run these steps:[56] Let route be a route .[57] For each element child in element 's children :[58] Process child with route ,
using the following table:l local name f Field r Rule l name
f name r String l desc
f description r String l cmt
f comment r String l src
f source r String l type
f type r String l number
f number r Non-negative number l link
f links r Link [60] If child 's local name is rtept
:[61] Append the result of parsing a point element child
to route 's points .[162] Return route .
[63] To parse a track element element , run these steps:[64] Let track be a track .[65] For each element child in element 's children :[66] Process child with track ,
using the following table:l local name f Field r Rule l name
f name r String l desc
f description r String l cmt
f comment r String l src
f source r String l type
f type r String l number
f number r Non-negative number l link
f links r Link [67] If child 's local name is trkseg
:[70] Let segment be a track segment .[76] For each element gc in child 's children :[77] If gc 's local name is trkpt
:[80] Append the result of parsing a point element gc
to segment 's points .[75] Append segment to track 's segments .[163] Return track .
[105] The rules for parsing a latitude value text are as given in the following algorithm:[106] Let number be the result of applying the
rules for parsing floating-point number values to text .[107] If number is not a number, return null and abort these steps.[108] If number is greater than 90 , or less than -90 ,
return null and abort these steps.[109] Return number .
[110] The rules for parsing a longitude value text are as given in the following algorithm:[111] Let number be the result of applying the
rules for parsing floating-point number values to text .[112] If number is not a number, return null and abort these steps.[113] If number is greater than 180 , or less than -180 ,
return null and abort these steps.[114] Return number .
[153] To process a value element element with object and table ,
run these steps:[156] Let row be a row in table , whose "local name "
cell value is element 's local name .[142] If row is null , abort these steps.[155] Let field be row 's "Field" cell value.[164] If object 's field 's value is not null
, abort these steps.[157] Let result be the result of switching by row 's "Rule" cell value:String [149] Let text be element 's child text content .[150] If text is not the empty string :[151] Return text .[148] Otherwise:[152] Return null .Non-negative number [135] Let text be element 's child text content .[136] Let number be the result of applying the
rules for parsing non-negative integers to text .[137] If number is a number:[138] Return number .[139] Otherwise:[140] Return null .Number [120] Let text be element 's child text content .[121] Let number be the result of applying the
rules for parsing floating-point number values to text .[122] If number is a number:[119] Return number .[128] Otherwise:[129] Return null .Degree [125] Let text be element 's child text content .[126] Let number be the result of applying the
rules for parsing floating-point number values to text .[127] If number is a number in the range [ 0 , 360 ]:[124] Return number .[132] Otherwise:[133] Return null .Year [36] Let text be element 's child text content .[37] If text is four or more ASCII digits :[38] Let year be the result of applying the rules for parsing non-negative integers to text .[41] If year is a positive integer:[39] Return year and abort these steps.[3] Return null .Time [16] Let text be element 's child text content .[117] Parse a global date and time string
text .[123] If a time is returned:[130] Return the time.[131] Otherwise:[134] Return null .URL Content [81] Let text be element 's child text content .[82] If text is not the empty string ,
parse text relative to element 's node document .[93] If parsed and not failed:[94] Return the resulting URL string .[95] Otherwise:[96] Return null .Link [190] Let href be element 's href
attribute value .[191] If href is not null ,
parse href relative to element 's node document .[192] If parsed and not failed:[200] Let link be a new link .[201] Set link 's URL to the resulting URL string .[203] For each element child in element 's children :[204] Process child with link ,
using the following table:l local name f Field r Rule l text
f text r String l type
f MIME type r String l link
f URL r URL [193] Return link .[194] Otherwise:[195] Return null .Person [42] Let person be a new person .[68] For each element child in element 's children :[23] Process child with person ,
using the following table:l local name f Field r Rule l name
f name r String l link
f links r Link [69] If child 's local name is email
and person 's email is null :[46] Let left be child 's id
attribute value.[47] Let right be child 's domain
attribute value.[48] If left and right are not null :[50] Let email be left followed by @
followed by right .[49] Set person 's email to email .[44] Return person .License [55] Let license be a new license .[7] Let holder be
element 's author
attribute value.[8] If holder is not null and is not the empty string :[54] Set license 's holder to holder .[53] For each element child in element 's children :[24] Process child with license ,
using the following table:l local name f Field r Rule l year
f year r Year l license
f URL r URL Content [28] Return license .[158] If result is not null :[196] If object 's field field is a list :[199] Append result to object 's field field 's value.[197] Otherwise:[198] Set object 's field field to result .
[172]
The gpx
element in the GPX namespace
MAY
have a tzoffset
attribute
in the GPX extension namespace .
If specified,
its value
MUST
be a
valid time-zone offset string .
It is the time-zone offset that is appropriate as
the default time-zone offset
for rendering timestamps in the element .
[214]
The wpt
element in the GPX namespace
MAY
have a pointrole
attribute
in the GPX extension namespace .
If specified,
its value
MUST
be a
valid point role string .
It is the kind of the point in the context of a race (or similar) event
described by the document.
[215]
A valid point role string
is one of followings:
String Description globalStart
The first start point of the race. globalGoal
The last goal point of the race. partialStart
The start point of one of the subsections of the entire route of the race (which is not categorized as globalStart
). partialGoal
The goal point of one of the subsections of the entire route of the race (which is not categorized as globalGoal
). checkpoint
One of intermediate points during the route of the race which serves a remarkable role in the race, typically known as aid station, checkpoint, or gate. observer
A point that does not belong to any other kind.
[216]
How to use these roles, including how points are associated with
the routes in the same document, are application dependent.
[217]
An application might impose additional context-specific constraints
for GPX document it handles. For example, an application
might require that the first point in the route
has to be the same location with the point whose
pointrole
is globalStart
.
[175]
The trkpt
element in the GPX namespace
MAY
have a road
attribute
in the GPX extension namespace .
If specified,
its value
MUST
be a
valid road type string .
It is the kind or condition of the road
at the point of the element .
[176] A valid road type string is one of followings:
String Description p
A road paved by e.g. concrete or asphalt d
A dirt road u
A completely unpaved path
[35]
The trkpt
element in the GPX namespace
MAY
have a todistance
attribute
in the GPX extension namespace .
If specified,
its value
MUST
be a
valid floating-point number
that
parses
to a number greater than or equal to 0 .
It is the distance between this
and the previous
points (i.e. the points represented by this and the nearest previous sibling
trkpt
elements in the GPX namespace ),
in meters .
If there is no previous point,
the number MUST be equal to 0 .
If the distance is not known,
the attribute MUST NOT be specified.
[209] To determine the distance between track points
point1 and point2 , run these steps:
[210] Assert :
point1 and point2
are both contained in the points
of the same
track segment
and
point2
immediately
follows
point1
in the points .[211]
If point2 's
to distance
is not
null
:[212]
Return point2 's to distance .[213]
Return the distance between points
(point1 's latitide , point1 's longitude )
and
(point2 's latitide , point2 's longitude ),
determined by an
implementation-dependent algorithm.[208]
The term
meter https://www.bipm.org/en/publications/si-brochure/metre.html
is defined by the
SI Brochure: The International System of Units (SI) .
[165] This specification depends on the Infra Standard .
The terms
list ,
append ,
contains ,
for each ,
size ,
and
is empty ,
are defined by the Infra Standard .
[167]
The terms
MIME type
and
essence
are defined by the MIME Sniffing Standard .
[5] The terms
previous sibling ,
element , attribute ,
value ,
Document
,
document element ,
node document ,
children , local name ,
and namespace are defined by the DOM Standard .
[34] The terms ASCII digits ,
rules for parsing non-negative integers ,
valid floating-point number ,
rules for parsing floating-point number values ,
parse a global date and time string ,
child text content ,
valid time-zone offset string ,
parse a time-zone offset string ,
parse a URL ,
resulting URL string ,
and
XML parser ,
are defined by the HTML Standard .
[178]
Elements in the GPX namespace and
its attributes
are defined by the GPX specification
https://www.topografix.com/gpx.asp .