lua-users home
lua-l archive

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


Andy Stark wrote:

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"...}

Nope, lua dosn't accept nil as an index.

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).

A generic lua table to XML conversion should be trivial. Something like the follow jumps to mind:

root = {
 ["something"]="one";
 "two",
 { ["another"]="three" }
}

...becomes...

<table name="root">
 <item name="something">one</item>
 <item name="1">two</item>
 <table name="2">
    <item name="another">three</item>
 </table>
</table>

Could probably make it even simpler, but there is no real problem in the direction.

The trick to remember is that a lua table and an XML document are two very diffrent structures so we can't expect a simple one to one relationship between them.

Scott Morgan