acid.xml
This library is considered production ready.
Convert lua table to xml or xml to lua table.
local xml = require('acid.xml')
local xml_str, err, errmsg = xml.to_xml('root', {foo='bar'})
if err ~= nil then
ngx.say('error')
end
-- <root><foo>bar</foo></root>
local r, err, errmsg = xml.from_xml('<foo>bar</foo>')
if err ~= nil then
ngx.say('error')
end
-- r.foo == 'bar'
syntax:
xml_str, err, errmsg = xml.to_xml(root_name, tbl, opts)
arguments:
-
root_name
: The root tag name. -
tbl
: Arbitrary lua table, support the following extra fields.-
__attr
: A table to set attributes. -
__key_order
: A array table to specify the output label order.
-
-
opts
: The options table accepts the following options:-
no_declaration
: If true, will not add declaration string. -
indent
: Set the indent to get a beautiful output.
-
return: The xml formated string.
syntax:
r, err, errmsg = xml.from_xml(xml_str)
arguments:
xml_str
: Xml formated string.
return: A lua table.
Renzhi (任稚) [email protected]
The MIT License (MIT)
Copyright (c) 2015 Renzhi (任稚) [email protected]