Children Container fix
This commit is contained in:
@@ -144,29 +144,6 @@ local function createTableFromNode(node, scope)
|
|||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
local Container = {}
|
|
||||||
function Container:loadXML(content, scope)
|
|
||||||
scope = scope or {}
|
|
||||||
local nodes = XMLParser.parseText(content)
|
|
||||||
self:fromXML(nodes, scope)
|
|
||||||
end
|
|
||||||
|
|
||||||
local baseFromXml
|
|
||||||
function Container.setup()
|
|
||||||
baseFromXml = require("elementManager").getElement("BaseElement").fromXML
|
|
||||||
end
|
|
||||||
|
|
||||||
function Container:fromXML(content, scope)
|
|
||||||
baseFromXml(self, content, scope)
|
|
||||||
for _, node in ipairs(content) do
|
|
||||||
local capitalizedName = node.tag:sub(1,1):upper() .. node.tag:sub(2)
|
|
||||||
if self["add"..capitalizedName] then
|
|
||||||
local element = self["add"..capitalizedName](self)
|
|
||||||
element:fromXML(node, scope)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local BaseElement = {}
|
local BaseElement = {}
|
||||||
function BaseElement:fromXML(node, scope)
|
function BaseElement:fromXML(node, scope)
|
||||||
if(node.attributes)then
|
if(node.attributes)then
|
||||||
@@ -206,8 +183,6 @@ function BaseElement:fromXML(node, scope)
|
|||||||
table.insert(args, convertValue(child.value, scope))
|
table.insert(args, convertValue(child.value, scope))
|
||||||
elseif (child.tag == "table")then
|
elseif (child.tag == "table")then
|
||||||
table.insert(args, createTableFromNode(child, scope))
|
table.insert(args, createTableFromNode(child, scope))
|
||||||
else
|
|
||||||
errorManager.error("XMLParser: unknown child '" .. child.tag .. "' in element '" .. self:getType() .. "'")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -220,14 +195,41 @@ function BaseElement:fromXML(node, scope)
|
|||||||
else
|
else
|
||||||
self[child.tag](self)
|
self[child.tag](self)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
errorManager.error("XMLParser: method '" .. child.tag .. "' not found in element '" .. self:getType() .. "'")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local Container = {}
|
||||||
|
function Container:loadXML(content, scope)
|
||||||
|
scope = scope or {}
|
||||||
|
local nodes = XMLParser.parseText(content)
|
||||||
|
self:fromXML(nodes, scope)
|
||||||
|
if(nodes)then
|
||||||
|
for _, node in ipairs(nodes) do
|
||||||
|
local capitalizedName = node.tag:sub(1,1):upper() .. node.tag:sub(2)
|
||||||
|
if self["add"..capitalizedName] then
|
||||||
|
local element = self["add"..capitalizedName](self)
|
||||||
|
element:fromXML(node, scope)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Container:fromXML(nodes, scope)
|
||||||
|
BaseElement.fromXML(self, nodes, scope)
|
||||||
|
if(nodes.children)then
|
||||||
|
for _, node in ipairs(nodes.children) do
|
||||||
|
local capitalizedName = node.tag:sub(1,1):upper() .. node.tag:sub(2)
|
||||||
|
if self["add"..capitalizedName] then
|
||||||
|
local element = self["add"..capitalizedName](self)
|
||||||
|
element:fromXML(node, scope)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
API = XMLParser,
|
API = XMLParser,
|
||||||
Container = Container,
|
Container = Container,
|
||||||
|
|||||||
Reference in New Issue
Block a user