Skip to content
Sudheer edited this page Jan 14, 2023 · 11 revisions

XSD schema processor for lua

lua_schema provides tools and class libraries to achieve XSD schema processing and XML and JSON parsing in lua

  • gxsd: Tool to parse XSD files and transform the rules within, to their expression in lua
  • schema_processor: A lua class to access the message handler of an element by one of the means
    • From the code generated by gxsd, by locating the lua file in the installed directory based on manespace and element names
    • From the xsd file by dynamically generating the handler code
Usage: gxsd  all/<xsd_file_name> [ -b 1/0 ] [ -d <output_directory> ]
       -b : optional,  build mode or local mode
       -d : optional, output directory to which the generated lua module should be written
  • Message handler: A generated class from element declaration. Message handler provides features for handling of XML and JSON files.
    • Generate a JSON string from lua table (object), based on XSD schema
    • Generate an XML document from lua table (object) based on XSD schema
    • Validate if a given lua table (object) is correct vis-a-vis the XSD rules
    • Parse an XML as per XSD schema to generate a lua table (object)
    • Parse a JSON string as per XSD schema to generate a lua table (object)

Initialization

Once gxsd is run on the xsd files, the generated lua modules should be deployed in an approriate direcoty mentioned in LUA_PATH environmental variable.
namespace is required in case of such element declarations which have namespace mentioned in the XSD file

local schema_processor = require("schema_processor");
local message_handler = schema_processor:get_message_handler("<element name>" [, "<namespace>"]);

Deserialize

--[[
If ther is any errro lua_obj will be returned as nil and the err_msg will have the description of error
]]

local lua_obj, err_msg = message_handler:from_xml(xml_string);
local lua_obj, err_msg = message_handler:from_json(json_string);

Serialize

--[[
If ther is any errro lua_obj will be returned as nil and the err_msg will have the description of error
]]

local xml_string, err_msg = message_handler:to_xml(lua_obj);
local json_string, err_msg = message_handler:to_json(lua_obj);

Validate

local valid, err_msg = message_handler:validate(lua_obj);
Clone this wiki locally