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
 

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:
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
 
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

 
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.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…