An open API service indexing awesome lists of open source software.

https://github.com/xiyoo0812/luaxml

lua bindings for tinyxml2!
https://github.com/xiyoo0812/luaxml

lua xml

Last synced: 11 days ago
JSON representation

lua bindings for tinyxml2!

Awesome Lists containing this project

README

        

# luaxml
lua bindings for tinyxml2(https://github.com/leethomason/tinyxml2).

# 依赖
- [lua](https://github.com/xiyoo0812/lua.git)5.3以上
- [luakit](https://github.com/xiyoo0812/luakit.git)一个luabind库
- [tinyxml2](https://github.com/leethomason/tinyxml2),源码已经包含在内
- 项目路径如下

|--proj

 |--lua

 |--luaxml

 |--luakit

# 接口说明
```lua
local xml = require("luaxml")
--编码
--value: 输入的lua table
--header: xml的自定义头,不传使用默认
--res:输出xml字符串
--err:错误信息
local res, err = xml.encode(value)
local res, err = xml.encode(value, 'xml version="1.0" encoding="gbk"')

--解码
--value: 输入的xml字符串
--res:输出lua
local res = xml.decode(value)

--保存到文件
--xmlfile: 保存的xml文件名
--value: 输入的lua
--header: xml的自定义头,不传使用默认
--res:成功或者失败
local ok = xml.save("./bb.xml", xxlua, 'xml version="1.0" encoding="gbk"')

--从文件读取
--xmlfile: 读取的xml文件名
--res:输出xml字符串
--err:错误信息
local flua, ferr = xml.open("./bb.xml")

```

# 用法参考
```lua
--本示例使用了quanta引擎
--https://github.com/xiyoo0812/quanta.git

local log_dump = logger.dump

local cxml = [[



Jäne.Roe@tübingen.com
0.5.0
2004-11-23 - 2006-08-18
a demonstration application for veLib Lua scripting
[ -i(ini.xml) ]


veLua
0
0.0
0
0
24
0

800
600
0.5 0.6 0.7



1.0 1.0 1.0 0.2
1.0 0.0 1.0 0.7
0.0 0.5 1.0 0.7
1.0 1.0 1.0 1.0

-1.0
-1.0
1.0
1.0


0 1 2 3 4 5
1 1 1 1 1 1
0 0 0 0 0 0



0.1
2000
-1.0
1.0
-.75
.75
1




1
330.0
1.0






















]]

local xlua, err = xml.decode(cxml)
log_dump("luaxml decode err: {}, xml:{}", err, xlua)
local exml = xml.encode(xlua)
log_dump("luaxml encode xml:{}", exml)

local xxlua = xml.decode(cxml)
local ok = xml.save("./bb.xml", xxlua, 'xml version="1.0" encoding="gbk"')
log_dump("luaxml save xml:{}", ok)
local flua, ferr = xml.open("./bb.xml")
log_dump("luaxml open err: {}, xml:{}", ferr, flua)

```