Commit 92432ec2 authored by Jean-Philippe André's avatar Jean-Philippe André

Lua: fix module simplexml using the new API

parent 06fb88fa
...@@ -36,16 +36,15 @@ local function parsexml(stream, errormsg) ...@@ -36,16 +36,15 @@ local function parsexml(stream, errormsg)
local tree local tree
local parents = {} local parents = {}
local nodetype = reader:next_node() local nodetype, nodename = reader:next_node()
while nodetype > 0 do while nodetype > 0 do
--print(nodetype, reader:name())
if nodetype == 1 then if nodetype == 1 then
local name = reader:name() local node = { name= nodename, attributes= {}, children= {} }
local node = { name= '', attributes= {}, children= {} } local attr = reader:next_attr()
node.name = name while attr ~= nil do
while reader:next_attr() == 0 do node.attributes[attr] = reader:value()
node.attributes[reader:name()] = reader:value() attr = reader:next_attr()
end end
if tree then if tree then
table.insert(tree.children, node) table.insert(tree.children, node)
...@@ -54,10 +53,8 @@ local function parsexml(stream, errormsg) ...@@ -54,10 +53,8 @@ local function parsexml(stream, errormsg)
tree = node tree = node
elseif nodetype == 2 then elseif nodetype == 2 then
if #parents > 0 then if #parents > 0 then
local name = reader:name()
local tmp = {} local tmp = {}
--print(name, tree.name, #parents) while nodename ~= tree.name do
while name ~= tree.name do
if #parents == 0 then if #parents == 0 then
error("XML parser error/faulty logic") error("XML parser error/faulty logic")
end end
...@@ -80,6 +77,7 @@ local function parsexml(stream, errormsg) ...@@ -80,6 +77,7 @@ local function parsexml(stream, errormsg)
elseif nodetype == 3 then elseif nodetype == 3 then
table.insert(tree.children, reader:value()) table.insert(tree.children, reader:value())
end end
nodetype, nodename = reader:next_node()
end end
if #parents > 0 then if #parents > 0 then
...@@ -108,3 +106,4 @@ function add_name_maps(tree) ...@@ -108,3 +106,4 @@ function add_name_maps(tree)
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment