lua-users home
lua-l archive

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

On 21/08/16 02:50 PM, Marc Balmer wrote:
Am 22.08.2016 um 05:38 schrieb Martin <>:

On 16-08-21 07:45 AM, Marc Balmer wrote:
I am working on code to easily create XML trees from Lua tables.  What would,
in your opinion, be a comfortable Lua table notation of XML trees, expressed
as Lua tables?

For me for structure like

  <el attr1="value1", attr2="value2">
  <el attr1="value1", attr2="value2">

expressions "[1].value" or
"[].attrs['attr2']" looks convenient.

I don't want to access XML from Lua, I want to represent data as Lua tables,
which can then be converted to XML.  I want to _PRODUCE_ xml, not parse

Treat tables as lists.

You may want the first element to be a tag name. Alternatively you may want the element [0] to be a tag name.

For attributes, treat them as string keys.

Namespaces are a pain. I'm not sure how to handle them personally. Last time I played with "XML" I couldn't figure out how to handle attribute namespaces, but for tag namespaces you can just use [0] = {tag=tagname, ns=tagns}. (Or alternatively, use plain old [0] = "ns:tag". The thing with my XML-like thingy is that it allows anything in names and namespaces so I can't use a string representation. But you can!)

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.