Loading ...
Sorry, an error occurred while loading the content.

Adding GPX to existing C++ project

Expand Messages
  • Mark Wigmore
    Hi! I have a 3D graphics package written in C++ and OpenGL and I ve been asked to add a GPX file reader to it. I ve not used XML before and I was wondering if
    Message 1 of 7 , Aug 9, 2005
    • 0 Attachment
      Hi!

      I have a 3D graphics package written in C++ and OpenGL and I've been
      asked to add a GPX file reader to it. I've not used XML before and I
      was wondering if anyone here could give me some pointers to get me
      started.

      So far I've downloaded the MSXML 3.0 SDK, but it all seems gibberish
      to me! Most of the examples seem to be in VB too. I've tried
      implementing the C++ example for the DOMDocument2schemas() method,
      but it keeps failing on the line:

      _bstr_t namespaceURI(_T("http://www.topografix.com/GPX/1/1"));
      hr = pIXMLDOMSchemaCollection->add(namespaceURI, _variant_t(_T
      ("C:\\MyProjects\\XML\\gpx.xsd")));

      hr is always E_FAIL. :-(

      Thanks in anticipation!

      Mark
    • azbithead
      ... For a good, quick introduction to XML and XML-related technologies check out http://www.w3schools.com/. Beyond that, there are numerous books on the
      Message 2 of 7 , Aug 9, 2005
      • 0 Attachment
        --- In gpsxml@yahoogroups.com, "Mark Wigmore" <yahoo@m...> wrote:

        > I've not used XML before and I
        > was wondering if anyone here could give me some pointers to get me
        > started.

        For a good, quick introduction to XML and XML-related technologies
        check out http://www.w3schools.com/. Beyond that, there are numerous
        books on the subject.

        > So far I've downloaded the MSXML 3.0 SDK, but it all seems
        gibberish
        > to me!

        FWIW, we have implemented XML parsing in our C++ projects using the
        Xerces parser (http://xml.apache.org/xerces-c/index.html) and it has
        worked well for us. We looked at MSXML but didn't really like it. I
        will also say that if you're just starting out with XML you got a bit
        of a large task ahead of you. However, I think it's worth the effort
        as XML is a powerful technology.

        - Steve
      • Mark Wigmore
        ... Thanks for the advice. ... I thought XML was supposed to be this wonderful technology that would solve everyone s data file problems! Surely it should be a
        Message 3 of 7 , Aug 9, 2005
        • 0 Attachment
          --- In gpsxml@yahoogroups.com, "azbithead" <azbithead@g...> wrote:

          Thanks for the advice.

          > will also say that if you're just starting out with XML you got a bit
          > of a large task ahead of you.

          I thought XML was supposed to be this wonderful technology that would
          solve everyone's data file problems! Surely it should be a simple
          matter of plugging in a library and having simple commands, like
          ReadXMLFile() and GetXMLData()!!!

          Bring back binary files. At least you knew where you were with them. ;-)

          Mark
        • azbithead
          ... Oh, how I wish that life was that simple. ... Yeah, usually in a hex editor. ;-) - Steve
          Message 4 of 7 , Aug 9, 2005
          • 0 Attachment
            --- In gpsxml@yahoogroups.com, "Mark Wigmore" <yahoo@m...> wrote:

            > Surely it should be a simple
            > matter of plugging in a library and having simple commands, like
            > ReadXMLFile() and GetXMLData()!!!

            Oh, how I wish that life was that simple.

            > Bring back binary files. At least you knew where you were with them.

            Yeah, usually in a hex editor. ;-)

            - Steve
          • Radu Sora
            We are really not far from that. Meaning in the current parsers we have ReadXMLFile(), GetXMLData(). What we don t have is like ReadGpxFile(),
            Message 5 of 7 , Aug 9, 2005
            • 0 Attachment
              We are really not far from that. Meaning in the current parsers we have
              ReadXMLFile(), GetXMLData().



              What we don't have is like ReadGpxFile(), PutWaypointsInMyDatabase(), etc.
              Anyway, the entire "dirty job" is done by the parsers, seems normal to me.



              --

              Radu Sora

              Giscover.com

              Chief Developer



              _____

              From: Mark Wigmore [mailto:yahoo@...]
              Sent: 9 august 2005 20:13
              To: gpsxml@yahoogroups.com
              Subject: [gpsxml] Re: Adding GPX to existing C++ project



              --- In gpsxml@yahoogroups.com, "azbithead" <azbithead@g...> wrote:

              Thanks for the advice.

              > will also say that if you're just starting out with XML you got a bit
              > of a large task ahead of you.

              I thought XML was supposed to be this wonderful technology that would
              solve everyone's data file problems! Surely it should be a simple
              matter of plugging in a library and having simple commands, like
              ReadXMLFile() and GetXMLData()!!!



              Bring back binary files. At least you knew where you were with them. ;-)

              Mark



              [Non-text portions of this message have been removed]
            • Michael Collinson
              Mark, An alternative approach to using the schema is just to parse the GPX XML directly and pull out what you are looking for. Less elegant in the long run
              Message 6 of 7 , Aug 9, 2005
              • 0 Attachment
                Mark,

                An alternative approach to using the schema is just to parse the GPX XML
                directly and pull out what you are looking for. Less elegant in the long
                run perhaps but much faster to implement immediately ... and get ones head
                around it.

                Are you able to use MS .NET framework in your C++ project? Here's the C#
                code for a very simple parser to read GPS trackpoint lat, lon, elevation
                which I adapted from code some kind soul provided on the Internet so I hope
                it is useful in turn. Should be straight forward to adapt to
                C++. Exception handling needs adding.

                using System.Xml;

                // ...

                // Set to read the input GPX file as XML
                XmlTextReader reader = new XmlTextReader(@"c:\gpx");

                GpsTrackPoint trackpoint = null; // My object for
                storing each track point found, code not provided

                // Read each XML node
                while (reader.Read())
                {
                if (reader.Name == "trkpt" && reader.NodeType ==
                XmlNodeType.Element)
                {
                // Start a new trackpoint object and add
                lat / lon to it (they are attributes of <trkpt>)
                trackpoint = new GpsTrackPoint(); //
                Your constructor goes here

                while (reader.MoveToNextAttribute())
                {
                // Read the attributes. TODO MUST
                CATCH EXCEPTIONS HERE!!
                if ( reader.Name == "lat")
                {trackpoint.latitude = System.Convert.ToDouble(reader.Value); }
                if ( reader.Name == "lon")
                {trackpoint.longitude = System.Convert.ToDouble(reader.Value); }
                }

                }
                else if (reader.Name == "trkpt" && reader.NodeType
                == XmlNodeType.EndElement)
                {
                // We have got to the end of the <trkpt>
                // Add trackpoint object to this
                Collection and close object
                this.Add( trackpoint); // <-- I am adding
                the trackpoint to a predefined object Collection, code not provided
                trackpoint = null;
                }
                else if (reader.Name == "ele" && reader.NodeType
                == XmlNodeType.Element)
                {
                // Add elevation / altitude to the track
                point (it is a tag by itself)
                while (reader.NodeType !=
                XmlNodeType.Text) reader.Read();
                trackpoint.altitude =
                System.Convert.ToDouble(reader.Value); //TODO MUST CATCH EXCEPTIONS
                HERE!!

                }

                }

                Mike


                At 04:24 PM 9/08/2005 +0000, Mark Wigmore wrote:
                >Hi!
                >
                >I have a 3D graphics package written in C++ and OpenGL and I've been
                >asked to add a GPX file reader to it. I've not used XML before and I
                >was wondering if anyone here could give me some pointers to get me
                >started.
                >
                >So far I've downloaded the MSXML 3.0 SDK, but it all seems gibberish
                >to me! Most of the examples seem to be in VB too. I've tried
                >implementing the C++ example for the DOMDocument2schemas() method,
                >but it keeps failing on the line:
                >
                >_bstr_t
                >namespaceURI(_T("<http://www.topografix.com/GPX/1/1>http://www.topografix.com/GPX/1/1"));
                >hr = pIXMLDOMSchemaCollection->add(namespaceURI, _variant_t(_T
                >("C:\\MyProjects\\XML\\gpx.xsd")));
                >
                >hr is always E_FAIL. :-(
                >
                >Thanks in anticipation!
                >
                >Mark


                [Non-text portions of this message have been removed]
              • Mark Wigmore
                ... GPX XML ... the long ... ones head ... I had thought of doing that but was under the impression XML was more plug-and-play that it seems to be. ... Have
                Message 7 of 7 , Aug 10, 2005
                • 0 Attachment
                  --- In gpsxml@yahoogroups.com, Michael Collinson <mikes@a...> wrote:
                  > Mark,
                  >
                  > An alternative approach to using the schema is just to parse the
                  GPX XML
                  > directly and pull out what you are looking for. Less elegant in
                  the long
                  > run perhaps but much faster to implement immediately ... and get
                  ones head
                  > around it.

                  I had thought of doing that but was under the impression XML was more
                  plug-and-play that it seems to be.

                  > Are you able to use MS .NET framework in your C++ project?

                  Have been avoiding it as much as possible. It's a graphics-intensive
                  real-time 3D app and I can do without the massive overheads of .NET.

                  Many thanks for the code snippet. I shall have a good browse through
                  it.

                  Regards,

                  Mark
                Your message has been successfully submitted and would be delivered to recipients shortly.