lua-users home
lua-l archive

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



On Mar 26, 2009, at 4:31 PM, Tuomo Valkonen wrote:

One would expect there to be a gazillion feature-rich libraries
for parsing and printing all sorts of XML, and yet they're all
so primitive... yet not primitive enough.

Talking of primitive, here is another one:

http://dev.alt.textdrive.com/browser/HTTP/XML.lua

-- Follows David Sklar's BadgerFish convention for translating an XML document into a Lua table.
--
-- http://badgerfish.ning.com/
--
-- 1. Element names become table keys.
--
-- 2. Text content of elements goes in the '$' key of a table.
--    <alice>bob</alice>
--    becomes
--    { alice  = { [ '$' ] = 'bob' } }
--
-- 3. Nested elements become nested tables.
--    <alice><bob>charlie</bob><david>edgar</david></alice>
--    becomes
-- { alice = { bob = { [ '$' ] = 'charlie' }, david = { [ '$' ] = 'edgar' } } }
--
-- 4. Multiple elements at the same level become list elements.
--    <alice><bob>charlie</bob><bob>david</bob></alice>
--    becomes
-- { alice = { bob = { { [ '$' ] = 'charlie' }, { [ '$' ] = 'david' } } } }
--
-- 5. Attributes go in keys whose names begin with '@'.
--    <alice charlie="david">bob</alice>
--    becomes
--    { alice: { [ '$' ] = 'bob', [ '@charlie' ] = 'david' } }
--

Cheers,

--
PA.
http://alt.textdrive.com/nanoki/