[gdal-dev] writing encoding into GPX files

Even Rouault even.rouault at mines-paris.org
Tue Jan 31 09:29:11 EST 2012

Selon "Pouliot, Christopher (DNR)" <Christopher.Pouliot at state.mn.us>:

> Hello all,
> I'm writing GPX files with OGR and the documentation states:  "The content
> returned by OGR will be encoded in UTF-8, after the conversion from the
> encoding mentionned in the file header is."

Note that the quoted sentence mentions what happens when reading a GPX file.
Here you are interested by the writing part of the driver, for which the doc
also says "When writing a GPX file, the driver expects UTF-8 content to be
passed in." ;-)

> When my GPX file is written out it does not include the  encoding="UTF-8" in
> the head tag.  Is there a way to have it be written?

Short answer : no. Longer answer below.

> This is what I get:  <?xml version="1.0"?>
> This is what I'd like:  <?xml version="1.0" encoding="UTF-8"?>
> I'm using GPSBabel to upload these GPX files to GPS units and it is not
> reading my GPX files unless the encoding is specified.

My understanding of http://www.w3.org/TR/REC-xml/#NT-EncodingDecl and
particularly the following sentence ("""In the absence of information provided
by an external transport protocol (e.g. HTTP or MIME), it is a fatal error for
an entity including an encoding declaration to be presented to the XML processor
in an encoding other than that named in the declaration, or for an entity which
begins with neither a Byte Order Mark nor an encoding declaration to use an
encoding other than UTF-8.""") is that if encoding is not specified then the
encoding is assumed to be UTF-8.

So if my understanding of the spec is correct, I'd suggest you to file :
- one ticket for GPSBabel so that it can accepts the files without the encoding
- and an enhancement ticket in GDAL Trac so that it explicitely writes the UTF-8
encoding to avoid ambiguities.

In the meantime, you text editor is your best friend.

> Thanks!
> Chris
> Chris Pouliot
> GIS Application Developer
> Minnesota Department of Natural Resources
> christopher.pouliot at state.mn.us
> (651) 259-5491


More information about the gdal-dev mailing list