Help needed with ConvertXMLToArray

2015-03-18 Thread Graham Samuel
Hi

The very useful function ‘ConvertXMLToArray’ was written by Trevor deVore and 
included in Mike Doub’s MasterLibrary. So if you don't know this function or 
aren't willing to look at it, please skip this question and sorry for the waste 
of bandwidth.

My problem is that I’m using it, but I can’t understand it. I’m getting 
elements of an array with numeric labels attached to them, looking like

 myNode[1003]

The relevant bit of the documentation of this function is this:

 Node names will retain the sequence information (i.e. node[1], node[2], etc.).
 This information is necessary to determine order that keys should be
 processed in.   for example:
  set the itemDelimiter to [
  put the keys of theArray into theKeys
  sort theKeys numeric by the last item of each

There's a problem with this, in that the number in square brackets in my 
example is just a decimal number of variable length, so that for example [9] 
will occur in the sequence and so will [1000]. If you do a numeric sort by 
these numbers, 1000 will come before 9. So the format ought to be [0009] for a 
data set with a maximum of  nodes. Without this, an XML file with child 
nodes in a certain order will end up in a different order when converted to an 
array - and an order that isn't that easy to modify at this point.

Quite frankly I have no idea how to cause this function to produce the data in 
the correct sort order, because I still find both XML and arrays very tricky 
topics. I see that it's something to do with child nodes, but how do these 
nodes get their numbers and how can they be formatted in a different way?

If anyone can see the solution easily and has the time to look at the function 
in the MasterLibrary, I'd be grateful. Meanwhile, it's back to chunk 
expressions.

Graham



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Help needed with ConvertXMLToArray

2015-03-18 Thread Richard Gaskin

Graham Samuel wrote:

 If you do a numeric sort by these numbers, 1000 will come before 9.

If a numeric sort produces that outcome either the data isn't purely 
numeric or you've found a bug.



 Without this, an XML file with child nodes in a certain order will
 end up in a different order when converted to an array - and an order
 that isn't that easy to modify at this point.

LiveCode's arrays are associative arrays, in which elements have no 
inherent order relative to one another.


Keys are associated with values by a hash that determines the memory 
location of the value, and like most hashes the result maintains no 
metadata which describes either insertion order or order relative to 
other key values.


We can access array elements with a sense of order by first obtaining 
the keys and sorting those in whatever way is needed for the task at 
hand (numeric, alphanumeric, dateTime, etc.; provided of course the sort 
command works as questioned above).


--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode