-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.lua
35 lines (30 loc) · 995 Bytes
/
test2.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local function print_r(root)
local cache = { [root] = "." }
local function _dump(t, space, name)
local temp = {}
for k, v in pairs(t) do
local key = tostring(k)
if cache[v] then
table.insert(temp, "+" .. key .. " {" .. cache[v] .. "}")
elseif type(v) == "table" then
local new_key = name .. "." .. key
cache[v] = new_key
table.insert(temp,
"+" .. key .. _dump(v, space .. (next(t, k) and "|" or " ") .. string.rep(" ", #key), new_key))
else
table.insert(temp, "+" .. key .. " [" .. tostring(v) .. "]")
end
end
return table.concat(temp, "\n" .. space)
end
print(_dump(root, "", ""))
end
local f = assert(io.open("test.xml", "r"))
local xml = f:read("a")
f:close()
local lxml = require "luaxml"
local lx1 = lxml.new()
lx1:load(xml)
-- print_r(lx1.xt)
print(lx1)
lx1:save('test2.xml')