Navigating XML in LiveCode

Pete pete at mollysrevenge.com
Sun Jan 22 14:06:52 EST 2012


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


-- 
Pete
Molly's Revenge <http://www.mollysrevenge.com>



More information about the use-livecode mailing list