lua-users home
lua-l archive

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


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

Tables can be indexed associatively by strings or by integers, right? A
table should represent the root XML element. A string-indexed element of
this table should represent the XML tag:-

	<person>
	
	</person>

...becomes:-

	xmlRoot = {_tag_ = "person" ... }

 Attributes of the element should become table elements indexed by
strings:-

	<person version = "1.0">
		...
	</person>

...becomes:-

	xmlRoot = {_tag_ = "person", version = "1.0" ... }

Enclosed attributes and text should become integer-indexed elements. Each
of these would be in the same form as the root element:-

	<person version = "1.0">
		<name format = "normal">Dougie Vipond</name>
		<occupation>Ice Warrior</occupation>
		Some other text.
	</person>

...becomes:-

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

&.