Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
ffcolor
Posts: 9
Registered: ‎09-30-2009
My Device: Not Specified
Accepted Solution

GPX file XML parser

Hi,

 

I wonder how to retrieve GPS information from GPX file. The GPX file is also XML file, but I cannot get "lat" and "lon" values from the file.

 

The GPX file:

 

<?xml version='1.0' encoding='UTF-8' ?>
<gpx version="1.1" creator="85" xmlns="http://www.mooncity.pl" xmlns:nmea="http://www.mooncity.pl">
  <trk>
    <trkseg>
      <trkpt lat="12.273434000" lon="10.993777000">
        <ele>150.0</ele>
        <time>2009-08-22T11:25:41+01:00</time>
        <fix>2d</fix>
        <sat>7</sat>
      </trkpt>

 

The code:

 

   //xml
          String _node,_element;
         try {
          DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory. newInstance();
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                docBuilder.isValidating();
         Document doc;
         doc = docBuilder.parse(fc.openInputStream());
          doc.getDocumentElement ().normalize ();
                //NodeList list=doc.getElementsByTagName("*");
                 Element root=doc.getDocumentElement();
                NodeList list=root.getChildNodes();
                _node=new String();
                _element = new String();
                //this "for" loop is used to parse through the
                //XML document and extract all elements and their
                //value, so they can be displayed on the device

                for (int i=0;i<list.getLength();i++){
                    Node value=list.item(i).
                      getChildNodes().item(0);
                 System.out.print
                 (list.item(i).getNodeName());
                 System.out.println(value.getNodeValue());
                
               //  _element=value.getNodeValue();
                // System.out.println
                 //   (list.item(i).getNodeValue());
              //  System.out.println
                //( _element=value.getNodeValue();
              //      updateField(_node,_element);
         
                     //   (_node,_element);
                }//end for
        }
         catch (Exception e){
                System.out.println(e.toString());
            }
                    
         //xml end

 

The output from the program:

 

gpx
trk
trkseg     
trkpt
ele150.0
time2009-08-22T11:25:41+01:00
fix2d
sat7

 

 

Missing values:

 

lat="12.273434000" lon="10.993777000"

 

Is there other method or parser for GPX files??

Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: GPX file XML parser

You have to get the attributes to read those values.. using  getAttributes method. You could could google around to find examples of xml parsing.

Use Search. "Accept Solution" If the problem is resolved.