ABC of arrays
Michael Doub
mikedoub at gmail.com
Wed Apr 1 17:19:09 EDT 2015
Graham,
I think one of the things that is confusing you as you are trying to
learn arrays is the fact that you are looking at output created by
ConvertXMLToArray. ConvertXMLToArray is working as designed, but it
just happens to create key in a syntax that looks like a livecode array
reference. LiveCode keys are just strings, so ConvertXMLToArray is
adding a open bracket, a counter, and a close bracket when it sees
multiples of a xml tag, to make it unique within the array.
This makes perfect sense technically but I can see where it could really
confuse someone trying to figure out livecode arrays.
-= Mike
On 4/1/15 3:48 PM, Graham Samuel wrote:
> Well, Richard, I am always very willing to believe that I’ve misunderstood something, but this is what happened (this material is extracted from conversations I had on this list in the middle of March).
>
> 1. I had an XML file - it was actually a .gpx file, which shows a geographical route as a series of waypoints. The ‘top level’ of this structure is ‘gpx’. I mean the first three lines are (watch for wordwrap):
>
> <?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>
>
> 2. I converted it to an array using the function ConvertXMLToArray, by Trevor deVore - from Mike Doub’s Master Library.
>
> 3. I put the result into an array called ‘gGeneralArray’ - I can see this in the IDE as a nested structure.
>
> 4. I executed
>
> put the keys of gGeneralArray
>
> in the message box, and got the result
>
> gpx
>
> 5. I discussed this on the use-list, and Mike Bonner suggested
>
>> try
>> put the keys of gGeneralArray["gpx”]
>> and you'll get the next level of keys.
> 6. I did that and got
>
> wpt[1]
> trk
> @attributes
> wpt[4]
> wpt[2]
> metadata
> wpt[3]
>
> I just did this all again to prove to myself that I hadn’t made an obvious error.I am definitely only dealing with one array, so I can’t explain this, and the LC dictionary certainly doesn’t help.
>
> Tell me where I went wrong!
>
> Graham
>
>> On 1 Apr 2015, at 18:27, Richard Gaskin <ambassador at fourthworld.com> wrote:
>>
>> Graham Samuel wrote:
>>> And some things are just wrong: for example the very simple statement
>>>
>>> put the keys of myArray
>>>
>>> may or may not list all the keys, or it may. I have never understood
>>> this, especially as the Dictionary doesn’t discuss such ambiguities.
>> The Dictionary doesn't describe that because it should never happen.
>>
>> Under what circumstances would "the keys" not returns the keys?
>>
>> FWIW, I've only seen "the keys" return all keys in every version of LC/MC I've ever used.
> _______________________________________________
> 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