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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Developer
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??

Highlighted
Developer
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.