博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
luaxml 确实好用,节点检索超方便
阅读量:7065 次
发布时间:2019-06-28

本文共 1515 字,大约阅读时间需要 5 分钟。

  项目的配置文件是XML,项目中用了脚本语言LUA 5.3,找了几个lua解析xml的库,测试都不怎么样,有些是因为LUA的版本比较旧,用得话还得转(虽然工作量不大),最后找到了luaxml ,发现节点检索超方便。

  

xml = require('LuaXml')-- load XML data from file "test.xml" into local table xfilelocal xfile = xml.load("test.xml")print(type(xfile))-- search for substatement having the tag "scene"local xscene = xfile:find("id","id","5")-- if this substatement is foundif xscene ~= 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.")for i,node in pairs(xfile:find("root")) do    print("tag is ",node.tag)    if node.tag~=nil and node[node.tag]=="id" then    print(node.id,node.buildLevel,node.upGrade)    endendlocal f2 = xml.load("test2.xml")local section = f2:find("section","id","0")local difficulty=section:find("difficulty","id","1")local level=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 be 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.

 有个坑,

xml = require('LuaXml')这里一定要设置为全局的,加个local会出事的

http://viremo.eludi.net/LuaXML/index.html#download

转载于:https://www.cnblogs.com/loker/p/4378772.html

你可能感兴趣的文章
heartbeat高可用+lvsDR
查看>>
方丈被害子女有没有权利继承遗产?
查看>>
java入门第一季5、6
查看>>
[转载] 闻一多——七子之歌
查看>>
针对tomcat日志乱码问题
查看>>
免费的协作和协同办公软件平台onlyoffice轻松部署
查看>>
WiFi覆盖下的生活 享受便利的同时 别忘记了安全
查看>>
关于ios 8 7 下的模态窗口大小的控制 代碼+場景(mainstoryboard)( Resizing UIModalPresentationFormSheet )...
查看>>
Linux软件包的管理--YUM
查看>>
Axis2发布webservice(1)--0配置发布
查看>>
Java Web笔记 – Servlet中的Filter过滤器的介绍和使用 编写过滤器
查看>>
我奋斗了18年,不是为了和你一起喝咖啡
查看>>
gearman简单介绍
查看>>
《Typecript 入门教程》 3、接口
查看>>
jsp的几种跳转比较
查看>>
用oracle查询当前数据库中的所有表
查看>>
决心书
查看>>
git 从版本控制中删除文件及.gitignore的用法
查看>>
cacti安装
查看>>
Spark核心概念
查看>>