The project's configuration file is XML, the project uses the scripting language LUA 5.3, find a few LUA parsing XML library, testing is not good, some because the version of Lua is older, with the words also have to turn (although the workload is not large), finally found the luaxml, found that the node retrieval super convenient.
XML =require('Luaxml')--load XML data from file ' Test.xml ' into local table XFileLocalXFile = XML.Load("Test.xml")Print(type(xfile))--Search for substatement has the tag "scene"LocalXscene = Xfile:find ("ID","ID","5")--If this substatement is foundifXscene ~=Nil Then --Print it to screen Print(Xscene)--print tag, attribute ID and first substatement Print(Xscene.id,xscene.buildlevel)End--xfile:save "T.xml"Print("---\nready.") forI,nodeinch Pairs(Xfile:find ("Root")) Do Print("Tag is", Node.tag)ifnode.tag~=Nil andnode[node.tag]=="ID" Then Print(Node.id,node.buildlevel,node.upgrade)EndEndLocalF2 = XML.Load("Test2.xml")LocalSection = F2:find (" Section","ID","0")LocalDifficulty=section:find ("Difficulty","ID","1")LocalLevel=difficulty:find (" Level","ID","0")Print(Level.point)
function Xml.find (Var, tag, Attributekey,attributevalue)
Recursively parses a Lua table for a substatement fitting to the provided tag and attribute
- param Var, the table to is searched in.
- param tag (optional) The XML tag to be found.
- param Attributekey (optional) The exact attribute to be found.
- param AttributeValue (optional) The attribute value to be found.
- Returns the first (sub-) table which matches the search condition or nil.
Http://viremo.eludi.net/LuaXML/index.html#download
Luaxml really good, node retrieval super Convenient