-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimpleSaxParse.p
More file actions
78 lines (65 loc) · 2.39 KB
/
SimpleSaxParse.p
File metadata and controls
78 lines (65 loc) · 2.39 KB
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
/*
* Prog: SimpleSaxParse.p
* Desc: Program to put contents from xml in a flat tt
* Auth: Patrick Tingen (PT)
*
* ---------- --- -------------------------------------------------------------------
* 2004-03-01 PT Created
* 2007-04-16 PT Added parent# and child# to tt.
*/
define input parameter pcXmlFile as character no-undo.
define variable hParser as handle no-undo.
define variable hHandler as handle no-undo.
define variable iRecord as integer no-undo.
define variable cStartingElement as character no-undo.
define variable cStartFolder as character no-undo.
define temp-table ttElement no-undo
field iId as integer format '>>>9' label 'Seq#'
field iParentNr as integer format '>>>9' label 'Parent#'
field iChildNr as integer format '>>>9' label 'Child#'
field cName as character format 'x(150)' label 'Element'
field cAttr as character format 'x(8)' label 'Attribute'
field cValue as character format 'x(20)' label 'Value'
field lOpen as logical initial true
index idxPrim as primary iId
index idxOpen lOpen iId
.
/* Where are we running from? */
file-info:file-name = this-procedure:file-name.
cStartFolder = replace(file-info:full-pathname,"\","/").
cStartFolder = substring(cStartFolder,1,r-index(cStartFolder,'/')).
/* Run the handler procedure */
run value(cStartFolder + 'SimpleCallBack.p') persistent set hHandler.
/* initialize the sax reader */
create sax-reader hParser.
hParser:handler = hHandler.
/* set document to parse */
hParser:set-input-source('file', cStartFolder + pcXmlFile).
hParser:sax-parse() no-error.
/* errors? */
if error-status:error then
do:
if error-status:num-messages > 0 then
message error-status:get-message(1) view-as alert-box info buttons ok.
else
message return-value view-as alert-box info buttons ok.
end.
run getTable in hHandler ( output table ttElement ).
output to value(cStartFolder + 'sax-output.txt').
for each ttElement:
display
ttElement.iId
ttElement.iParentNr
ttElement.iChildNr
ttElement.cName
ttElement.cAttr
ttElement.cValue
with width 400 stream-io.
end.
output close.
os-command no-wait start value(cStartFolder + 'sax-output.txt').
finally:
/* clean up */
delete object hHandler.
delete object hParser.
end finally.