GPX parsers - gps-touring/cmd-line-tools GitHub Wiki
GPX Parsers
Creating GPX parsers from XML Schema
There exists XML schema for GPX 1.1. This page contains notes on experiments aimed at generating a GPX parser from this XSD.
Progress report
Get the XSD file:
gps-touring/cmd-line-tools/gpx-parser$ git clone https://github.com/rubyjedi/soap4r.git
Experiment with soap4r
This answer on stackoverflow leads us to look at https://github.com/rubyjedi/soap4r.
$ git clone https://github.com/rubyjedi/soap4r.git
$ sudo gem install soap4r-ng -n/usr/local/bin
(-n/usr/local/bin is a work-around for recent versions of Mac OS/X (see stackoverflow - probably not needed on linux)
Does xsd2ruby.rb run?
soap4r$ bin/xsd2ruby.rb
Usage: bin/xsd2ruby.rb --xsd xsd_location [options]
xsd_location: filename or URL
Example:
bin/xsd2ruby.rb --xsd myapp.xsd --classdef foo
Options:
--xsd xsd_location
--classdef [filenameprefix]
--mapping_registry
--mapper
--module_path [Module::Path::Name]
--force
--quiet
So far so good. Can it generate ruby?
soap4r$ bin/xsd2ruby.rb --xsd ../gps-touring/cmd-line-tools/gpx-parser/gpx1_1.xsd --classdef foo
I, [2017-03-20T12:36:54.965942 #12870] INFO -- app: Creating class definition.
I, [2017-03-20T12:36:54.966046 #12870] INFO -- app: Creates file 'foo.rb'.
I, [2017-03-20T12:36:54.987978 #12870] INFO -- app: End of app. (status: 0)
soap4r$ less foo.rb
soap4r$ ruby foo.rb
So we have generated ruby classes that correspond to the XSD.
Unfortunately, the generated code does not contain a parser.
This means that we would need to use an XML library (e.g. nokogiri) to parse the GPX,
and call the constructors in the generated foo.rb.
Looking at the generated code in foo.rb, there seems to be no use of the low-level type information (e.g. xsd:decimal) from the XSD -- that is not a good thing!
Conclusion for now: The xsd2ruby.rb script from soap4r is lacking some vital ingredients.
Experiment with rxsd
RXSD looked promising, but on following the usage example (after substituting the GPX XSD and a GPX file into their example), the example crashed. It seems that I had managed to reproduce an RXSD bug.
Conclusion: RXSD does not work for the GPX example I gave it.