-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.lua
More file actions
executable file
·39 lines (34 loc) · 908 Bytes
/
example.lua
File metadata and controls
executable file
·39 lines (34 loc) · 908 Bytes
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
36
37
38
39
#!/usr/bin/env lua
function printelem(e, prefix)
prefix = prefix or ''
if e.tag then
print(prefix .. '<' .. e.tag .. '>')
prefix = ' ' .. prefix
for name, value in pairs(e.attrs) do
print(prefix .. '@' .. name .. ': ' .. value)
end
for i, child in pairs(e.children) do
printelem(child, prefix)
end
else
print(prefix .. '<> ' .. e.text)
end
end
function printdoc(doc)
print('Entities:')
for i, e in pairs(doc.entities) do
print(' ' .. e.name .. ': ' .. e.value)
end
print('Data:')
for i, child in pairs(doc.children) do
printelem(child, ' ')
end
end
local parseFile = require('xmllpegparser').parseFile
local filename = arg[1] and #arg[1] > 0 and arg[1] or 'example.xml'
local replaceEntities = arg[2] and #arg[2] > 0
local doc, err = parseFile(filename, replaceEntities)
printdoc(doc)
if err then
io.stderr:write(err .. '\n')
end