|
Andy Stark wrote:
Has there been any standerd way of representing a XML document in a lua table structure defined yet?Here's a way I would like to see standardised in all languages that could support it...xmlRoot = {_tag_ = "person", version = "1.0"; {_tag_ = "name", format = "normal"; "Dougie Vipond", }, {_tag_="occupation"; "Ice Warrior", }, "Some other text", } (Lua automatically adds the [0], [1]... sequentially if you don't specify an index explicity. The semicolon after the attributes allows you to mix the string and integer indexing as shown on page 10 of the 5.0 manual. ).
I see a couple of problems here:1) What happens if you have xml like <item _tag_="PITA">, not likely , but possible.
2) Getting at the value held by the table is a bit difficult, in the 'name' and 'occupation' nodes it's at [1], but in the 'person' node it's at [3]. You could loop through the table looking for the first string, but what if you're using userdata to represent the text, or even worse a table (I can see situations where both would be useful for unicode support reasons). Idealy all values stored should not be assumed to be of type string.
This is exactly what I was thinking. We need a standard way to deal with this so we can create some helper functions to deal with it all.I agree that it would be great if this (or some better method) could be documented on the Lua website as a "standard" way to handle XML in Lua. At least for simple tasks.
Scott Morgan