Help needed with ConvertXMLToArray

Graham Samuel livfoss at mac.com
Wed Mar 18 09:59:23 EDT 2015


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






More information about the use-livecode mailing list