lua-users home
lua-l archive

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


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: pgpsYcJPvgeon.pgp
Description: PGP signature