lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Scott Morgan:-

>This seems over kill to my mind as its much simpler to push all the 
>attribute key/values into their own sub table.

There are other ways. You can index a table by any value, so we could have
a convention where the nil value, say, could be used as the index for the
XML tag:-

xmlRoot = {[nil]= "person"...}

It would be easy to define "tag = nil" to make the code more readable if
required, but it would work without this. It seems slightly more "natural"
to me not to have a separate sub-table for attributes; it maintains the
element == table identity and means you write "xmlRoot.name" instead of
"xmlRoot.attr.name" each time.

We would require any XML export module to:-
- Render string-indexed table elements as attributes;
- Render integer-indexed table elements as sub-elements;
- Use the nil-indexed table element as the tag text (or a generic "elem"
tag if there is no nil index).

This would mean that most Lua tables could be exported to XML reasonably
even if the author didn't originally design them to be used like this (ie,
most Lua tables are indexed either by strings or integers or both and
contain values which are either tables or values which can be converted
losslessly to strings).

&.