-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXMLMASKER
104 lines (95 loc) · 3.28 KB
/
XMLMASKER
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
SUBROUTINE XMLMASKER (OPVALUE,ACTION,IPVALUE)
* masks out invalid xml characters or puts them back
*$Copyright (c) 2010 TO 2012 to 2008 mike.ryder@pwchest.com, All Rights Reserved
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* Written by Mike Ryder @pwchest.com 16 March 2012
$CATALOG
$MODE UV.LOCATE
$INCLUDE I_WEBCOMMON
* A Generic routine to cope with "banned" XML characters
*
* OPVALUE - The returned value
* ACTION - 0 = outbound conversion
* 1 = inbound conversion
* IPVALUE - The text to change
* main *
GOSUB INITIALISE
OPVALUE = IPVALUE
IF ACTION THEN
GOSUB INBOUND
END ELSE
GOSUB OUTBOUND
END
RETURN
***************
* end of main *
***************
* subroutined *
***************
OUTBOUND:
* get rid of non-xml data
OPVALUE = CHANGE(OPVALUE, "&", "&")
OPVALUE = CHANGE(OPVALUE, "'", "'")
OPVALUE = CHANGE(OPVALUE, "xml", "x_m_l")
OPVALUE = CHANGE(OPVALUE,"field","f_ield")
OPVALUE = CHANGE(OPVALUE,"transaction","trans_action")
OPVALUE = CHANGE(OPVALUE, "<", "<")
OPVALUE = CHANGE(OPVALUE, ">",">")
OPVALUE = CHANGE(OPVALUE,CHAR(34), """)
OPVALUE = CHANGE(OPVALUE,CHAR(163), "£")
OPVALUE = CHANGE(OPVALUE,CHAR(165), "¥")
OPVALUE = CHANGE(OPVALUE,CHAR(128), "€")
OPVALUE = CHANGE(OPVALUE,CHAR(160), " ")
OPVALUE = CHANGE(OPVALUE,"-","–")
FOR J = 1 TO N.STRINGS
IXSTR = INSTRING[J,1]
OPVALUE = CHANGE(OPVALUE,IXSTR,"&#":SEQ(IXSTR):";")
NEXT J
RETURN
******
INBOUND:
* put back non-xml data
OPVALUE = CHANGE(OPVALUE,"'","'")
OPVALUE = CHANGE(OPVALUE,"x_m_l","xml")
OPVALUE = CHANGE(OPVALUE,"f_ield","field")
OPVALUE = CHANGE(OPVALUE,"trans_action","transaction")
OPVALUE = CHANGE(OPVALUE,"<","<")
OPVALUE = CHANGE(OPVALUE,">",">")
OPVALUE = CHANGE(OPVALUE,""",CHAR(34))
OPVALUE = CHANGE(OPVALUE,"£",CHAR(163))
OPVALUE = CHANGE(OPVALUE,"¥",CHAR(165))
OPVALUE = CHANGE(OPVALUE,"€",CHAR(128))
OPVALUE = CHANGE(OPVALUE," ",CHAR(160))
OPVALUE = CHANGE(OPVALUE,"–","-")
* this must be the last otherwise we get the other stuff corrupted
OPVALUE = CHANGE(OPVALUE,"&","&")
FOR J = 1 TO N.STRINGS
IXSTR = INSTRING[J,1]
OPVALUE = CHANGE(OPVALUE,"&#":SEQ(IXSTR):";",IXSTR)
NEXT J
RETURN
******
INITIALISE:
* Create a string to convert everything except A..Z and 0..9
* These should be converted to their HEX equivalents as 
 or &#nnn for decimal
INSTRING = EMPTY
FOR J = 1 TO 254
INSTRING := CHAR(J)
NEXT J
OUTSTRING = EMPTY
FOR J = 32 TO 126
OUTSTRING := CHAR(J)
NEXT J
OUTSTRING := CHAR(156)
CONVERT OUTSTRING TO EMPTY IN INSTRING
N.STRINGS = LEN(INSTRING)
RETURN
******
END