Navigating XML in LiveCode

Graham Samuel livfoss at mac.com
Mon Jan 23 11:34:24 EST 2012


Pete - thanks for your reply (the only one so far - are there no XML users on the list??). I understand that arrays would do the job, since the array structure in LC can be extended at will rather than having to be declared before use, although I'm not sure about a structure where some 'nodes' were missing - say in the employee database, if someone didn't have some characteristic like a parking slot etc then I would not want to create a null record just because some members of the employee set need one. I know that this missing out of unwanted nodes works really well in XML.

However the real reason that I'm trying to go down the XML route is that I need this data to persist and I don't want the overhead of storing it in a stack rather than just keeping a trivial amount of text which furthermore could be easily examined/edited by non-LC programs. When one looks at examples of XML, such as the one by Sarah Reichelt at

http://www.troz.net/rev/

I notice that people tend to use employee lists and the like; but so far I haven't found a very clear explanation of how you get attributes into new nodes at a stroke, which is my problem. (In fact I'm not really doing an employee database, but the concept is very similar.)

I suppose more generally I'm trying to understand if XML is suitable for this kind of data structure, where there are several nodes identical or similar in structure but containing different data. It looks ideal to me, but the difficulty of finding the last item you added, and of adding attributes at creation time, is giving me doubts. But maybe I'm just confused.

Graham

On Sun, 22 Jan 2012 11:06:52 -0800, Pete <pete at mollysrevenge.com> wrote:
> 
> Hi Graham,
> I'll say upfront that I'm not familiar with XML so I'm really suggesting an
> alternative rather than answering your question.
> 
> Have you thought about using LC arrays rather than XML for this?  LC arrays
> are lightning fast to access and I think would work great for a small
> dataset like this.
> 
> The major key of your array could be the EmployeeID with subkeys holding
> the various data values associated with the employee. With that type of
> structure and assuming you know the employee id up front, you would create
> your employee "node" with:
> 
> put theEmpID into theArray["EmployeeID"]
> 
> After that, you could populate the details with statements like:
> 
> put "John Doe" into theArray[theEmpID]["EmployeeName"]  etc....
> 
> Pete
> 
> 
> 
> 
> 
> On Sun, Jan 22, 2012 at 6:45 AM, Graham Samuel <livfoss at mac.com> wrote:
> 
>> For no special reason I have never used XML, either in LiveCode or
>> anywhere else. Now I'm scripting an app that calls for a tiny database
>> containing a number of similarly structured records (probably not more than
>> 50), with all the values essentially text or numbers easily expressible as
>> text. XML seems a good fit for this, but there are some odd bits I can't
>> understand despite reading Sarah Reichelt's useful tutorial and looking at
>> the LiveCode dictionary and the User Guide.
>> 
>> The issue is this - suppose I want to add a node to my data structure
>> before I have any data (attributes or node contents) to put into it: for
>> example in an employee list, I want to create an <employeeDetails> node as
>> a member of a set of nodes all with that name - I may want to add subnodes
>> too at the moment of creation, but that's not the real issue.
>> 
>> My next step will be to make that particular instance of <employeeDetails>
>> unique by giving it an attribute like say "EmployeeID" with a unique value.
>> The problem is that I can't apparently do this in one step, although I
>> would like to, so as to make sure that my new node can immediately be
>> identified, searched for etc. First I have to create the node, and
>> afterwards I want to add my attribute. But how can I find it? I suppose I
>> could search for a node that hasn't got an "EmployeeID" attribute yet, or I
>> could parse the whole structure to find the last node at that level, but
>> both these methods seems kind of crude. Is there some way to keep track of
>> the last node created, similar to LiveCode's feature within the creation of
>> new objects? If there is, I can't find it. Or maybe I'm just thinking about
>> it in the wrong way.
>> 
>> Any help would be appreciated, as ever.
>> 
>> Graham
> 




More information about the use-livecode mailing list