Navigating XML in LiveCode
livfoss at mac.com
Sun Jan 22 08:45:40 CST 2012
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.
More information about the use-livecode