• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Cluain/Lua-Simple-XML-Parser: Read simple XML easily

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

Cluain/Lua-Simple-XML-Parser

开源软件地址(OpenSource Url):

https://github.com/Cluain/Lua-Simple-XML-Parser

开源编程语言(OpenSource Language):

Lua 100.0%

开源软件介绍(OpenSource Introduction):

Installation

  1. Copy the xmlSimple.lua file to your project.
  2. Create a local variable local xml = require("xmlSimple.lua").newParser()
  3. Read xml using xml:ParseXmlText(xmlString) or xml:loadFile(xmlFilename, base)

Parsing XML

<test one="two">
    <three four="five" four="six"/>
    <three>eight</three>
    <nine ten="eleven">twelve</nine>
</test>

You can access values in two ways:

Using the simple method:

xml.test["@one"] == "two"
xml.test.nine["@ten"] == "eleven"
xml.test.nine:value() == "twelve"
xml.test.three[1]["@four"][1] == "five"
xml.test.three[1]["@four"][2] == "six"
xml.test.three[2]:value() == "eight"

or if your XML is a little bit more complicated you can do it like this:

xml:children()[1]:name() == "test"
xml:children()[1]:children()[2]:value() == "eight"
xml:properties()[1] == {name = "one", value = "two"}

Limitations

There's no support for namespaces. When I see namespaces I immediately start to remember days when I worked at corporate. We had to use namespaces only because XML was so convoluted we would not be able to handle it without them. In the end XML parsing took longer for some APIs then actual logic of the API. If you're in this situation it is better to step back and do something about it rather than asking for namespace support. I am using this module to read fairly simple XML. Even if it is a large XML string, the structure is still simple, so I was not able to test it properly. Please create a new Issue if you spot a problem. Please take a loook at xmlTest.lua for an example of use.

Final notes

This is a modified version of Corona-XML-Module by Jonathan Beebe which in turn is based on Alexander Makeev's Lua-only XML parser found here




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
cloudwu/luadebug: A lua debugger in independent lua VM发布时间:2022-08-16
下一篇:
xjdrew/lua-zset: lua data structure same as redis sorted set发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap