--- a/lm.lua Sat Mar 05 18:04:48 2016 +0200
+++ b/lm.lua Wed Mar 16 01:53:56 2016 +0200
@@ -196,34 +196,34 @@
end
end
--- TODO: multiple nodes with same name
-function lm.message_node.parse ( node, r )
+function lm.message_node.parse ( node )
+ -- attributes
+ local r = node:attributes ()
+ -- node value (text)
+ local value = n:value ()
+ if value then
+ s[1] = value
+ end
+ -- children nodes
local n = node:child ()
- while n do
+ for n in node:children () do
local name = n:name ()
- r[name] = { }
- local value = n:value ()
- if value then
- r[name][1] = value
+ if type ( r[name] ) ~= 'table' then
+ r[name] = { }
end
- lm.message_node.parse ( n, r[name] )
- n = n:next ()
+ table.insert ( r[name], lm.message_node.parse ( n ) )
end
+ return r
end
--- There are NO WAY to get a list of node attributes,
--- except brute force...
function lm.message.parse ( message )
+ local r = lm.message_node.parse ( message )
+ -- message type we treat in a special way
local mtype, subtype = message:type ()
if subtype then
mtype = mtype .. '-' .. subtype
end
- local r = { mtype = mtype }
- local value = message:value ()
- if value then
- r[1] = value
- end
- lm.message_node.parse ( message, r )
+ r['mtype'] = mtype
return r
end