lua-users home
lua-l archive

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


Scott Morgan wrote:
><person id="1234">
> <name>
>   <first>John</first>
>   <last>Smith</last>
> </name>
></person>

I'd go for something like:

xml = { node = "person", id = "1234";
    { node = "name";
        { node = "first";
            "John"
        },
        { node = "last";
            "Smith"
        }
    }
}

If you know the markups beforehand, you could write it like:

xml = person { id = "1234";
    name {
        first { "John" },
        last { "Smith" }
    }
}

where markups would be defined as:

function person( table )
    table.node = "person"
    -- here you can also check that the format is valid, ie.
ssert( table.id ~= nil )
end

Your second example would then be:

> <PARENT>
>   <CHILD>Timmy</CHILD>
>   <CHILD>Tommy</CHILD>
> </PARENT>

xml = parent {
    child { "Timmy" },
    child { "Tommy" }
}


Hope that helps,


Ignacio Castaño
castanyo@yahoo.es