lua-users home
lua-l archive

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


On Feb 11, 2006, at 1:41 PM, Asko Kauppi wrote:
Why do you (want to) have the .attr section there?

Just for name-collision issues with my element-name convenience. For example:

<person name="Bob" kids="2">
	<kids>
		<person name="Susie" />
		<person name="Billy" />
	</kids>
</person>

With my parser, that becomes:
{
	name="person",
	attr={
		name="Bob",
		kids="2"
	},
	[1]={
		name="kids",
		attr = {},
		[1] = {
			name="person",
			attr = { name="Susie" },
			elements = {}
		},
		[2] = {
			name="person",
			attr = { name="Billy" },
			elements = {}
		},
		elements = {
			person = {
				[1] = <the 'Susie' LOM table>,
				[2] = <the 'Billy' LOM table>
			}
		},
		person = <the 'Susie' LOM table>
	},
	elements = {
		kids = {
			[1] = <the 'kids' LOM table>
		}
	},
	kids = <the 'kids' LOM table>
}

Although I love the idea of putting attributes in the table itself, I decided to go the safer route so I can be sure that there will be no collisions between attributes of the element and 'meta' attributes I want convenient access to.


The [0] index as name is a neat way to avoid the collisions if you aren't going to have any other parser-generated attributes on the object, though.