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!
- Host: GitHub
- URL: https://github.com/xiyoo0812/luaxml
- Owner: xiyoo0812
- License: mit
- Created: 2024-05-08T07:05:26.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-03T08:13:05.000Z (3 months ago)
- Last Synced: 2025-05-07T08:58:17.501Z (11 days ago)
- Topics: lua, xml
- Language: C++
- Homepage:
- Size: 51.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.gitlocal 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
0800
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)```