XML Newbie Woes

Graham Samuel livfoss at mac.com
Mon Sep 23 15:44:15 EDT 2013


Hi Kay

Thanks for that really interesting insight. I think I'll do exactly what you say: what I want to do is to draw elevation graphs, simply to fill in a gap in the way this particular GPS data is presented by its native editor. I just want to extract a set (or array) of lines which are  name-value pairs representing x and y values on a graph, to see just how much up and down there was in each trek. I fully expect the authors of the original thing to catch up and make my work redundant, and I naively thought that with just a little effort I could do the thing in LC while I was waiting. Plus I would learn about XML and about my chosen graph-drawing plug-in, Chartmaker (thanks, Hugh). Actually I find I can do this minus the XML bit, using your method.

Going back to XML, I know I am totally ignorant of the subject, but I was alarmed both by the eccentricities of the format (a tree structure which is actually a set of parentheses, except when it's not...) and with the inability of the revXML series of handlers to allow one to analyse the structure of an XML in the abstract without knowing the names of all the tags, or whatever they're called, and the exact parenthetical structure. Since I have to know everything about the file, its structure and the names of all its labels (or node names, or tags, dunno) before I can operate on it, I might as well consciously ditch any attempt at generality and use that knowledge from the off and do what you did. Maybe I have imagined a set of XML operations  that does not and could not exist. A (very) little knowledge is a dangerous thing.

Thanks again

Graham

(whose internet service is back up, thank goodness)


On 22 Sep 2013, at 07:38, Kay C Lan wrote:

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