[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua+XML = forced love? (Re: FYI: what's OOP's jargons and complexities?)
- From: Javier Guerra <javier@...>
- Date: Sun, 30 Jan 2005 09:55:14 -0500
On Sunday 30 January 2005 9:47 am, Asko Kauppi wrote:
> ok. Can I also modify the table, then save it back..? ;)
that's a bit longer, here's what i use for output:
local function attrstostr (a)
local out = {}
for i,attr in ipairs (a) do
table.insert (out, string.format ('%s = "%s"', attr, a[attr]))
end
return table.concat (out, " ")
end
function lomtoxml (x, of)
of = of or print
if type (x) == "string" then
return of (x)
end
local attrs = ""
-- does it have any attributes?
if x.attr [1] then
attrs = " " .. attrstostr (x.attr)
end
-- is there any content?
if x[1] then
of ("<" .. x.tag .. attrs .. ">")
for i in ipairs (x) do
lomtoxml (x[i], of)
end
of ("</".. x.tag .. ">")
else
of ("<" .. x.tag .. attrs .. "/>")
end
end
--
Javier
Attachment:
pgpkHyZPWa302.pgp
Description: PGP signature