Android Question gpx extentions

MbedAndroid

Active Member
Licensed User
Longtime User
anyone knows how i should code these extentions with xmlbuilder?
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>90</gpxtpx:hr>
</gpxtpx:TrackPointExtension>
</extensions>
simply .element.text doesnt give the right output
 

DonManfred

Expert
Licensed User
Longtime User
Why use a lib for this simple format?

B4X:
dim xml as string = $"<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>90</gpxtpx:hr>
</gpxtpx:TrackPointExtension>
</extensions>"$
file.writestring(path,filename,xml)
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
it's only a part of the whole xml build Don
i got it working with libgpx but xmlbuild looks a nicer way to construct such things
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
looks promising Erel. Let's see how i can compose the xml with all other elements
<?xml version="1.0" encoding="UTF-8"?><trk>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>90</gpxtpx:hr>
</gpxtpx:TrackPointExtension>
</extensions>
</trk>
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
still not working. Everytime i face "unbound prefix" error message
tried this:
B4X:
    Dim m2x As Map2Xml
m2x.Initialize
Dim m As Map = CreateMap("extensions": CreateMap("gpxtpx:TrackPointExtension" : _
    CreateMap("gpxtpx:hr": 90)))
Log(m2x.MapToXml(m))
ParsedData = xm.Parse(m2x.MapToXml(m))
'fails here

output:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
trueresult
start
<?xml version="1.0" encoding="UTF-8"?><extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>90</gpxtpx:hr>
</gpxtpx:TrackPointExtension>
</extensions>
xml2map_parse2 (java line: 175)
org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column 4: unbound prefix
at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:519)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:478)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
at anywheresoftware.b4a.objects.SaxParser.parse(SaxParser.java:80)
at anywheresoftware.b4a.objects.SaxParser.Parse(SaxParser.java:73)
at b4a.example.xml2map._parse2(xml2map.java:175)
at b4a.example.xml2map._parse(xml2map.java:163)
at b4a.example.main$ResumableSub_Activity_Create.resume(main.java:544)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column 4: unbound prefix
stangly when i load a file from Strava or Ride with the same xml output, i can parse the xml.🤪
(also the same error when i build it with XMLbuilder)
Tried also namespace, no difference

this is a part of Strava orginal
<?xml version="1.0" encoding="UTF-8"?>
<gpx creator="StravaGPX" 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 http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">
<metadata>
<time>2020-08-18T12:43:36Z</time>
</metadata>
<trk>
<name>⛅ Middagrit</name>
<type>1</type>
<trkseg>
<trkpt lat="47.0620510" lon="1.4614270">
<ele>162.8</ele>
<time>2020-08-18T12:43:36Z</time>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>62</gpxtpx:hr>
<gpxtpx:cad>0</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
yes, but to check the xml is valid i parse it again. I noticed that when you upload the constructed file to one of those servers, the file isnt accepted with message " file doesnt contain any track"

Meanwhile i discovered that the tabspace is very important. 1 space extra and the server wont accept the file
example below is what today was recorded. The xml is valid, but wont accepted by the servers. If i reduce the tabsteps the server will accept it.
But there is no setting in the xmlbuilder to control the tabsteps

<?xml version="1.0" encoding="UTF-8"?><gpx>
<metadata>
<time>2020-08-25T14:50:21Z</time>
</metadata>
<trk>
<name>test gpx</name>
<type>1</type>
<trkseg>
<trkpnt lat="47.05469513" lon="001.45844281">
<ele>205</ele>
<time>2020-08-25T12:39:42Z</time>
<extentions>
<gpxtpx:TrackpointExtention>
<gpxtpx:hr>62</gpxtpx:hr>
<gpxtpx:cad>37</gpxtpx:cad>
</gpxtpx:TrackpointExtention>
</extentions>
</trkpnt>
<trkpnt lat="47.05469513" lon="001.45844269">
<ele>205</ele>
<time>2020-08-25T12:39:44Z</time>
<extentions>
<gpxtpx:TrackpointExtention>
<gpxtpx:hr>64</gpxtpx:hr>
<gpxtpx:cad>24</gpxtpx:cad>
</gpxtpx:TrackpointExtention>
</extentions>
</trkpnt>
 
Last edited:
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
if finally got it working for both servers. All made by xmlbuilder
For anyone looking for a gpx example,see below

B4X:
xm.Initialize
    DateTime.DateFormat = "yyyy-MM-dd"
    Private Zoffset= DateTime.GetTimeZoneOffsetAt(DateTime.Now) As Int
    DateTime.SetTimeZone(0)
    Dim x As XMLBuilder
    x = x.create("gpx")
    x.namespace($"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.cluetrust.com/XML/GPXDATA/1/0 http://www.cluetrust.com/Schemas/gpxdata10.xsd" version="1.1" creator="http://ridewithgps.com/">"$)
    x = x.element("metadata").element("name").text("test gpx").up() _
          .element("link").attribute("href","https://ridewithgps.com/trips/55290156") _
        .element("text").text("test gpx").up().up()
    x=x.element("time").text("2020-08-30T07:23:37Z").up().up()
    x = x.element("trk")
    x=x.element("name").text("test gpx").up()
    x=x.element("trkseg")
    Private timestart=DateTime.now As Long
    For tx=0 To 57
        Private lat=47.05471420288086 +0.1*Cos(tx/57) As Float
        Private lon=1.458349347114563 +0.1*Sin(tx/57) As Float
        Private alt=Rnd(800,1000) As Float
        Private hr=Rnd(60,70) As Int
        Private cd=Rnd(50,60) As Int
        timestart=timestart+tx*1000
'   
        Private timestring=DateTime.Date(timestart)&"T"&DateTime.time(timestart)&"Z" As String
        x=x.element("trkpt").attribute("lat", NumberFormat(lat,2,7)).attribute("lon", NumberFormat(lon,3,7))
        x=x.element("ele").text(NumberFormat(alt/10,1,5)).up()
        x=x.element("time").text(timestring).up()
        x=x.element("extentions")
        x=x.element("gpxdata:hr").text(hr).up()
        x=x.element("gpxdata:cadence").text(cd).up().up().up()
        '
    Next
    
   Dim props As Map
   props.Initialize
   props.Put("{http://xml.apache.org/xslt}indent-amount", "4")
   props.Put("indent", "yes")
     Private q As String
   q=(x.asString2(props))
    Private sf As StringFunctions
    sf.Initialize
    Private l As List
    l.Initialize
    l=sf.Split(q,CRLF)
    For xx=0 To l.Size-1
        Log(l.Get(xx))
    Next

this testprogram will give on strava or Ride following picture:
Note: the namespace is not really required.
Even i think the embedded link wasnt needed.

Screen Shot 08-30-20 at 11.01 PM.PNG
 
Upvote 0
Top