XML Newbie Woes

Kay C Lan lan.kc.macmail at gmail.com
Sun Sep 22 01:38:13 EDT 2013


What is it you exactly want to do with the gps data?

About 18 months back I needed to work with gps data and obvioulsy chose LC
for the project and logically the XML functions for the job. Like you, I
had a great deal of trouble with XML but soon realised that the gpx files
were so well 'worded' that LCs own word chunk expression was about 98% up
to the task. I think I did a bit of pre-pruning and then simply used a
repeat for each loop to go through every line of the file and place the
data into an array. Your data looks smaller than what I was dealing with,
mine had a time stamp every second and 8 data points associated with that
time. I simply created the array using the time as the primary key and data
headings as the secondary keys.

In my case I needed to transform gpx files into human readable data, so it
was a simple case of read the files in then close, process in LC, then
output the specific data. I know it took me one day to throw together the
script which was able to process 100+ files totalling just over 1 million
datapoints in a couple of seconds.

If your task is to fiddle with the gpx file itself and still have a valid
file format when done, then that may be more complex than what I was doing,
but again, the format is very straight forward and I think would still be
doable using LC's basic chunk expressions.

HTH


On Thu, Sep 19, 2013 at 12:19 AM, Graham Samuel <livfoss at mac.com> wrote:

> I have been asked to do some work on some GPX files: these files originate
> from GPS devices, and are in XML format. I've never had to deal with XML
> before, so I have been trying to learn how to do so from the LC user manual
> - from about page 189.  There is a sample XML file and a discussion of the
> various 'revXML' functions which are on offer. There are a few typos, but
> it doesn't **look** hard.
> (I don't have any other source of information since my crazy ISP has cut
> off my internet connection, and I am confined at present to emails sent &
> received via a friend.)
>
> So far, so good: however, although I can create an XML tree and retrieve
> the Root Node as per the documentation, I can't make any of the other
> functions work on my data. I hope someone can explain the fundamentals of
> what I'm doing wrong.
>
> My GPX file begins like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <gpx xmlns="http://www.topografix.com/GPX/1/1" creator="Geolives"
> 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 />
>   <trk>
>     <trkseg>
>       <trkpt lat="42.78981" lon="1.336446">
>         <ele>750.5912</ele>
>       </trkpt>
>       <trkpt lat="42.78981" lon="1.336446">
>         <ele>750.5912</ele>
>       </trkpt>
> [etc etc etc]
>
> The file seems to be well-formed, apart from the fact that the first child
> node is found by revXML to be "gpx/metadata", and I can't see the closure
> for the metadata tag at the other end of the document. In fact the document
> ends </gpx>f I try to stick in </metadata> before this last line, the LC
> function refuses to form the table, so the original file must be right. I
> don't understand this.
>
> Anyway, revXMLRootNode returns "gpx" (without the quotes)
>
> and revXMLFirstChild returns "/gpx/metadata"
>
> but after that nothing works. However closely I follow the example in the
> manual, I can't get the revXMLContents or revXMLNodeContents functions to
> return anything. For example (among many attempts),
> revXMLNodeContents(1,"/gpx/metadata/trk/trkseg") returns
>
> "xmlerr, can't find element"
>
> I feel like I've tried everything, but it seems there's something basic I
> haven't grasped. XML seems like a simple idea, but in practice it's
> dreadfully easy to slip up.
>
> TIA for any advice, as long as it doesn't mean significant downloading.
>
> Graham
>
>
> Sent from my iPad
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list