Luaxml really good, node retrieval super Convenient

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.