Naive XML questions

Graham Samuel livfoss at mac.com
Mon Oct 26 10:46:26 EDT 2020


Thanks to all who replied, but Ken - you are spot on! I simply had no idea how to address an individual node. I am not keen to use any method other than the ones which already exist in the XML library, so this is the way for me. 

One can sometimes (often, if I’m honest) be stymied by some very basic lack of knowledge. It reminds me vaguely of some consumer tests which were done on (I think) early IBM PCs. The researchers wanted to know how the new users got on with the machine, how productive it was for them etc, but they soon found that the most common issue was how to switch the machine on! In explaining stuff, we neglect the basics at our peril.

Graham

> On 25 Oct 2020, at 23:29, Ken Ray <kray at sonsothunder.com> wrote:
> 
> Graham, here's the basic approach (assuming your XML is in the variable 'tXML'):
> 
> 	put revXMLCreateTree(tXML,false,true,false) into tTreeID
> 	put  "/gpx/trk/trkseg/trkpt[1]" into tNode  -- the brackets identify the instance of "trkpt" to work with
> 	put revXMLAttribute(tTreeID, tNode,"lon") into tLonValue
> 	put revXMLNodeContents(tTreeID,(tNode & "/ele")) into tEleValue
> 	put tLonValue && "/" && tEleValue
> 
> >> 2.128369 / 169.623637
> 
> So to work with the third instance of "trkpt", you'd do:
> 
> 	put  "/gpx/trk/trkseg/trkpt[3]" into tNode
> 
> Hope this helps,
> 
> Ken
> 
> 
>> On Oct 25, 2020, at 12:21 PM, Graham Samuel via use-livecode <use-livecode at lists.runrev.com <mailto:use-livecode at lists.runrev.com>> wrote:
>> 
>> I feel stupid, but even with Sarah Reichelt’s help, there are very very simple things I can’t do with the LC XML functions. My current problem is this:
>> 
>> I have a series of XML files which are in fact .gpx files - a collection of GPS coordinates representing a route on the Earth’s surface. There are thousands of files around which I can use as test data, so I don’t have to roll my own. Taking just one of these examples, I can do the following in LC
>> 
>> 1. Get the user to find the file and download it
>> 
>> 2. Check it’s a .gpx file
>> 
>> 3. Turn it into an LC XML data structure with an integer ID
>> 
>> 4. Find out how many child nodes there are.
>> 
>> Then it all goes wrong, because I don’t seem to be able to address the individual nodes. This is obviously needed for further progress, in functions like revXMLFirstChild  and revXMLNodeContents.
>> 
>> I just don’t know what format to use. Sarah’s tutorial doesn’t help because her data structure is too simplified.
>> 
>> If you’re still with me, this is what the beginning of a typical file looks like:
>> 
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <gpx xmlns="http://www.topografix.com/GPX/1/1 <http://www.topografix.com/GPX/1/1>" creator="Digital Crow" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance <http://www.w3.org/2001/XMLSchema-instance>" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 <http://www.topografix.com/GPX/1/1> http://www.topografix.com/GPX/1/1/gpx.xsd <http://www.topografix.com/GPX/1/1/gpx.xsd>">
>>> <metadata />
>>> <trk>
>>>   <trkseg>
>> 
>>> <trkpt lat="43.319729" lon="2.128369">
>>> <ele>169.623637</ele> </trkpt>
>> 
>>> <trkpt lat="43.319731" lon="2.128375">
>>> <ele>169.744722</ele> </trkpt>
>> 
>>> <trkpt lat="43.319731" lon="2.128375">
>>> <ele>169.744722</ele> </trkpt>
>> 
>>> <trkpt lat="43.319731" lon="2.128388">
>>> <ele>169.266626</ele> </trkpt>
>>> 
>> etc - there may sometimes be thousands of these “trkpt” elements.
>> 
>> So, suppose I want to get the first instance of the “lon” attribute into a local variable. How do I address the first <trk> node etc in order to do it? I have attempted various common-sense methods, but none work.
>> 
>> This must be child’s play to a lot of people, just not me.
>> 
>> Hoping for some guidance.
>> 
>> Graham
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com <mailto: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
> 
> Ken Ray
> Sons of Thunder Software, Inc.
> Email: kray at sonsothunder.com <mailto:kray at sonsothunder.com>
> Website: https://www.sonsothunder.com
> 
> 
> 
> 




More information about the use-livecode mailing list