blob: 82316421162ff4372048c024e535207b8a2d1021 (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#!/usr/bin/lua
---Simple command line test parser - applies handler[s] specified
-- to XML file (or STDIN) and dumps results<br/>
--
-- $Id: testxml.lua,v 1.1.1.1 2001/11/28 06:11:33 paulc Exp $<br/>
--
-- $Log: testxml.lua,v $<br/>
-- Revision 1.1.1.1 2001/11/28 06:11:33 paulc<br/>
-- Initial Import
--
modxml = require('luaxml-mod-xml')
handler = require('luaxml-mod-handler')
pretty = require('luaxml-pretty')
-- Defaults
_print = nil
_simpletree = nil
_dom = nil
_file = nil
_xmlrpc = nil
_debug = nil
_ws = nil
_noentity = nil
_usage = [[
textxml.lua [-print] [-simpletree] [-dom] [-xmlrpc] [-debug]
[-ws] [-noentity] [-help] [file]
]]
_help = [[
testxml.lua - Simple command line XML processor
Options:
-print : Generate event dump (default)
-simpletree : Generate simple tree
-dom : Generate DOM-like tree
-debug : Print debug info (filename/text)
-ws : Do not strip whitespace
-noentity : Do not expand entities
-help : Print help
file : XML File (parse stdin in nil)
]]
index = 1
local exit = os.exit
function setOptions(x)
if _ws then
x.options.stripWS = nil
end
if _noentity then
x.options.expandEntities = nil
end
end
while arg[index] do
--print (arg[index])
if (string.sub(arg[index],1,1)=='-') then
if arg[index] == "-print" then
_print = 1
elseif arg[index] == "-simpletree" then
_simpletree= 1
elseif arg[index] == "-dom" then
_dom= 1
elseif arg[index] == "-xmlrpc" then
_xmlrpc= 1
elseif arg[index] == "-debug" then
_debug = 1
elseif arg[index] == "-ws" then
_ws = 1
elseif arg[index] == "-noentity" then
_noentity = 1
elseif arg[index] == "-help" then
print(_usage)
exit()
else
print(_usage)
exit()
end
else
-- Filename is last argument if present
if arg[index+1] then
print(_usage)
exit()
else
_file = arg[index]
end
end
index = index + 1
end
if _file then
print("File",_file)
if (_debug) then
io.write ( "File: ".._file.."\n" )
end
--xml = read(openfile(_file,"r"),"*a")
local f, e = io.open(_file, "r")
if f then
xml = f:read("*a")
else
error(e)
end
else
xml = io.read("*a")
end
if _debug then
io.write ( "----------- XML\n" )
io.write (xml.."\n")
end
if _print or not (_print or _dom or _simpletree or _print or _xmlrpc) then
io.write ( "----------- Print\n" )
h = handler.printHandler()
x = modxml.xmlParser(h)
setOptions(x)
x:parse(xml)
end
if _simpletree then
io.write ( "----------- SimpleTree\n" )
h = handler.simpleTreeHandler()
x = modxml.xmlParser(h)
setOptions(x)
x:parse(xml)
pretty.pretty('root',h.root)
end
if _dom then
io.write ( "----------- Dom\n" )
h = handler.domHandler()
x = modxml.xmlParser(h)
setOptions(x)
x:parse(xml)
pretty.pretty('root',h.root)
io.write ( "-----------\n" )
end
|