Module jls.util.xml
Provide XML codec.
The XML nodes are represented using table for elements and string for texts. The table is used as an array to store the XML node children. The table has the properties 'name' and optionally 'attr' to store the node name and the node attributes using a table with key value pairs.
Functions
xml.encode (xmlTable) | Returns the XML encoded string representing the specified table. |
xml.decode (xmlString) | Returns the XML table representing the specified XML string. |
Functions
- xml.encode (xmlTable)
-
Returns the XML encoded string representing the specified table.
Parameters:
- xmlTable table The XML table to encode.
Returns:
-
the encoded XML as a string.
Usage:
local xml = require('jls.util.xml') xml.encode({name = 'a', {name = 'b', attr = {c = 'c'}, 'A value'}}) -- Returns '<a><b c="c">A value</b></a>'
- xml.decode (xmlString)
-
Returns the XML table representing the specified XML string.
Parameters:
- xmlString string The XML string to decode.
Returns:
-
the decoded XML as a table.
Usage:
local xml = require('jls.util.xml') xml.decode('<a><b c="c">A value</b></a>') -- Returns {name = 'a', {name = 'b', attr = {c = 'c'}, 'A value'}}