Further dumb question about arrays

Mike Bonner bonnmike at gmail.com
Sat Mar 14 10:44:58 EDT 2015


>From your post, it looks like trk is on the same level as gpx?  So, you
would have myArray["trk"]  Then the next level.. it looks like your trkseg
and trkpt[] are on the different levels. (hard to see from the email, but
they pretty much have to be) So, you would have myarray["trk"]["trkseg"],
and could do an easy repeat for each at that point.

repeat for each key tKey in myarray["trk"]["trkseg"]
  do whatever with myArray["trk"]["trkseg"][tkey]["time*"]
end repeat

Another option to simplify would be to: put myArray["trk"]["trkseg"] into
myNewArray
and then you can
repeat for each key tKey in myNewArray
  do whatever with myNewArray[tKey]["time*"]
end repeat

If you need to pull out the data in numeric order (based on [1001] in the
brackets, you can put the keys in question into a list and do a sort

put the keys of myArray[whateverleveltostartat] into tKeys
set the itemdelimiter to "["
sort lines of tKeys numeric by item 2 of each

then just repeat for each line tLine in tKeys and pull the data out as
above using tLine as the key in question

On Sat, Mar 14, 2015 at 7:21 AM, Graham Samuel <livfoss at mac.com> wrote:

> Thanks to help from this list, I’ve used Trevor’s ‘ConvertXMLtoArray’ to
> convert an XML file into a multidimensional array. Looks good in the IDE,
> but I can’t understand how to access its elements by following the scraps
> of advice in the User Guide. The IDE says that my array (say ‘myArray’)
> looks like this
>
> gpx
>   @attributes
>   metadata
> trk
>   trkseg
>     trkpt[1001]
>       @attributes
>             lat*
>             lon*
>          ele*
>          time*
>     trkpt[1002]
>
>    etc (there are thousands of elements at the ’trkpt’ level)
>
> The lines marked with an asterisk have actual values, for example the
> ‘time’ element contains a time.
>
> I have tried to follow the documentation, but I can’t understand how to
> address a specific element, much less loop through the whole array. For
> instance, how would I get the time for trkpt[1001]? It must be obvious to
> many, but not to me. The general syntax seems to be of the form
>
>  put myArray[key1][key2]…[keyn] into someVariable
>
> where the keys are strings in quotes (or presumably expressions that
> evaluate to strings), but I haven’t hit on any sequence that just shows me
> one element, like the time.
>
> I feel stupid, but I have tried.
>
> Thanks for any clarification.
>
> Graham
> _______________________________________________
> 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