Skip to content

Instantly share code, notes, and snippets.

@d-led
Created October 4, 2012 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-led/3832071 to your computer and use it in GitHub Desktop.
Save d-led/3832071 to your computer and use it in GitHub Desktop.
usage of pugilua to view xml in a less verbose format
require('pugilua')
local function printattributes(node)
local res=''
local a=node:first_attribute()
while a.valid do
if #res>0 then res=res..',' end
res=res .. a.name .. '=' .. a.value
a=a:next_attribute()
end
if #res>0 then res='['..res..']' end
return res
end
local function printvalue(node)
local res=node.value
if not #res then return '' end
return res
end
local function printnode(node,depth,c)
local res=c or ''
res=res..string.rep(" ", depth) .. node.name .. ' ' .. printattributes(node) .. ' ' .. printvalue(node)..'\n'
------------------------------
local child=node:first_child()
while child.valid do
res=res..printnode(child,depth+1)
child=child:next()
end
return res
end
local doc=pugi.xml_document()
local res=doc:load_file [[..\pugilua.vcproj]]
print('Parsed: '..res.description)
assert(res.valid)
local text=printnode(doc:root(),-1)
print(text)
--local f = assert(io.open("dump.txt", "w"))
--f:write(text)
--f:close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment