diff options
author | spag <spag@golwen.net> | 2013-01-11 15:57:34 +0100 |
---|---|---|
committer | spag <spag@golwen.net> | 2013-01-11 15:57:34 +0100 |
commit | 55c1fccd239563be02013509f793685726d8bc6e (patch) | |
tree | b9b05d5b4154358892c4e778f6b38ad8aeb7c99c /misc/freeswitch/scripts/configuration/simple_xml.lua | |
parent | 69bd05e343fd5341d6b86517e5fad6d135436425 (diff) |
simple xml builder class added
Diffstat (limited to 'misc/freeswitch/scripts/configuration/simple_xml.lua')
-rw-r--r-- | misc/freeswitch/scripts/configuration/simple_xml.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/configuration/simple_xml.lua b/misc/freeswitch/scripts/configuration/simple_xml.lua new file mode 100644 index 0000000..f04dd1e --- /dev/null +++ b/misc/freeswitch/scripts/configuration/simple_xml.lua @@ -0,0 +1,50 @@ +-- Gemeinschaft 5 simple xml gererator class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +SimpleXml = {} + +-- Create SimpleXml object +function SimpleXml.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'simplexml'; + return object; +end + +function SimpleXml.element(self, arg) + local xml_tag = '<' .. tostring(arg[1]); + for key, value in pairs(arg) do + if type(key) == 'string' then + xml_tag = xml_tag .. ' ' .. tostring(key) .. '="' .. tostring(value) .. '"'; + end + end + xml_tag = xml_tag .. '>'; + + for key=2, #arg do + xml_tag = xml_tag .. '\n' .. tostring(arg[key]) .. '\n'; + end + + return xml_tag .. '</' .. tostring(arg[1]) .. '>'; +end + + +function SimpleXml.from_hash(self, element_name, parameter_hash, key_name, value_name) + local params_xml = ''; + for key, value in pairs(parameter_hash) do + local arguments = { [1] = element_name }; + if key_name and value_name then + arguments[key_name] = key; + arguments[value_name] = value; + else + arguments[key] = value; + end + params_xml = params_xml .. tostring(self:element(arguments)) .. '\n'; + end + + return params_xml; +end |