Hello together,
I can't figure out how to parse a gpx file.
Example:
What I think that i've understood is that e.g. lat and lon are attributes,
but ele and time are names. Attributes has to be catched by Parser_StartElement and Names by Parser_EndElement?!
my code so far:
The answer of the compiler:
Compiling code. 0.02
Compiling layouts code. 0.00
Generating R file. 0.22
Compiling generated Java code. Error
B4A line: 64
lati = Attributes.GetValue2(\
javac 1.6.0_26
src\b4a\example\main.java:482: inconvertible types
found : java.lang.String
required: org.xml.sax.Attributes
mostCurrent._lati.setObject((org.xml.sax.Attributes)(_attributes.GetValue2("","lat")));
^
1 error
I've declared lati and loni as attributes, that seems to be completly wrong. But how to?
And 2nd question: Can i ignore e.g. trkseg because it is only in a few gpx files?
I think, I didn't understand anything how the parser works.
Thank you for your attention!
Sorry for my English but I'm not used to!
I can't figure out how to parse a gpx file.
Example:
B4X:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="www.gps-tour.info" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<name>Rundwanderung Ratingen-Schwarzbach</name>
<author>
<name>Herbert Backhaus</name>
</author>
<link href="m.gps-tour.info/de/touren/detail.92930.html">
<text>Rundwanderung Ratingen-Schwarzbach on www.gps-tour.info</text>
</link>
<time>2012-09-16T08:42:01Z</time>
<bounds minlat="51.2701594" minlon="6.8771381" maxlat="51.284978" maxlon="6.9318763"/>
</metadata>
<wpt lat="51.2812461" lon="6.9167127">
<ele>134</ele>
<name>Bank mit netter Aussicht</name>
<sym>Waypoint</sym>
</wpt>
<wpt lat="51.2852097" lon="6.8775487">
<ele>68</ele>
<name>Start und Ziel</name>
<sym>Waypoint</sym>
</wpt>
<trk>
<name>Rundwanderung Ratingen-Schwarzbach</name>
<trkseg>
<trkpt lat="51.284978" lon="6.8772785">
<ele>73.2</ele>
<time>2012-09-16T08:42:01Z</time>
</trkpt>
<trkpt lat="51.2848808" lon="6.8771381">
<ele>71.3</ele>
<time>2012-09-16T08:42:15Z</time>
</trkpt>
<trkpt lat="51.2846029" lon="6.877505">
<ele>69.8</ele>
<time>2012-09-16T08:42:54Z</time>
</trkpt>
...
</trkseg>
</trk>
</gpx>
What I think that i've understood is that e.g. lat and lon are attributes,
but ele and time are names. Attributes has to be catched by Parser_StartElement and Names by Parser_EndElement?!
my code so far:
B4X:
Sub LoadFile_Click
Dim fd As FileDialog
fd.FastScroll = True
fd.FilePath = ""
fd.FileFilter = ".gpx"
ret = fd.Show("Choose a .gpx file", "Yes", "No", "", Null)
If ret=-1 Then
Dim FileToStr As String
FileToStr=File.ReadString(fd.FilePath, fd.ChosenName)
Msgbox(FileToStr,"") 'just to see what I'm doing
Else
Activity.Finish
End If
'parse the xml file
Dim In As InputStream
In = File.OpenInput(fd.FilePath, fd.ChosenName)
parser.Parse(In, "Parser")
In.Close
End Sub
Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
If Name="trkpt" Then
lati = Attributes.GetValue2("","lat")
Log(lati)
loni = Attributes.GetValue2("","lon")
Log(loni)
End If
End Sub
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
If parser.Parents.IndexOf("trkpt") > -1 Then
If Name = "ele" Then
elevation = Text.ToString
Log(elevation)
Else If Name = "time" Then
timestamp = Text.ToString
Log (timestamp)
End If
End If
If Name = "trkpt" Then
Log(elevation)
Log(timestamp)
End If
End Sub
The answer of the compiler:
Compiling code. 0.02
Compiling layouts code. 0.00
Generating R file. 0.22
Compiling generated Java code. Error
B4A line: 64
lati = Attributes.GetValue2(\
javac 1.6.0_26
src\b4a\example\main.java:482: inconvertible types
found : java.lang.String
required: org.xml.sax.Attributes
mostCurrent._lati.setObject((org.xml.sax.Attributes)(_attributes.GetValue2("","lat")));
^
1 error
I've declared lati and loni as attributes, that seems to be completly wrong. But how to?
And 2nd question: Can i ignore e.g. trkseg because it is only in a few gpx files?
I think, I didn't understand anything how the parser works.
Thank you for your attention!
Sorry for my English but I'm not used to!
Last edited: