lua-users home
lua-l archive

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


2011/10/11 Michal Kottman <k0mpjut0r@gmail.com>:
> On 10 October 2011 22:30, Florian Weimer <fw@deneb.enyo.de> wrote:
>>> On 10 October 2011 09:13, Eike Decker <zet23t@googlemail.com> wrote:
>>>> I am not aware of an xml lib that provides a simple access in Lua. What you
>>>> could consider however is to use Lua Expat [1] and use this to create a dom
>>>> like access pattern that matches exactly your needs. I think the required
>>>> code for this would be acceptably short and simple. It would probably come
>>>> closer to your actual needs than any existing library.
>>>>
>>>
>>> http://matthewwild.co.uk/projects/luaexpat/lom.html - I'm not sure it
>>> can get much simpler (except something like XPath maybe...).
>>
>> I would use a different encoding: node[0] for the tag, node[1] to
>> node[#node] for the children, and node[attr] for the value of the
>> attribute attr (a string).  This works because the order of attributes
>> does not matter.
>
> This is very similar to what I use in my little utility module WDM
> (Web Data Mining) [1]. It helps to save a lot of (IMHO unnecessary)
> tables.
>
> I use the following "encoding":
> * node[1] - node[#node] - children of the node
> * node[attr] - the node attribute (like div.style or link.href)
> * node.tag - the HTML tag, because 'tag' is not used as an attribute
> in (X)HTML, could be modified to 'xml' in case of XML files
>
> [1] https://github.com/mkottman/wdm
>
>
I just used following "encoding":
* node[0] or node.tagName - the HTML tag.
* array part of node - the children of node, the child is a table or string.
* hash part of node - the attribute of node.