XML library¶
LuaConnector has built-in xml library
Functions¶
parse¶
Performs conversion from string with xml data to table:
xml.parse(data)
Arguments¶
stringdata- string with xml
Returns¶
tableparsing result
Table structure is pretty simple. Every xml element has three fields:
stringnametableattributes (key-value pair array)tablechild (array of child elements)
get¶
Helper function for getting data from xml table:
xml.get(data, query)
Arguments¶
tabledata- xml table from
xml.parse
stringquery- query string for getting xml
Returns¶
table/stringrequested data
serialize¶
TODO
Query language¶
Query language description for xml.get
local string = [[
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<graphics>
<resolution ratio="1.65">1280x760</resolution>
<shadows>23</shadows>
</graphics>
<sound></sound>
</settings>
]]
local document = xml.parse(string)
xml.get(document, "settings/graphics/resolution") -- returns "1280x760"
xml.get(document, "settings/graphics/resolution/!") -- returns table with "resolution" element
xml.get(document, "settings/graphics/1") -- returns first element from "graphics" element
xml.get(document, "settings/graphics/[2]") -- returns first 2 elements from "graphics" element
xml.get(document, "settings/graphics/resolution[]") -- returns all attributes of "resolution"
xml.get(document, "settings/graphics/resolution[ratio]") -- returns "ratio" attribute of "resolution" element