1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.astrogrid.xmlutils;
22
23
24
25 import java.io.*;
26
27 import org.astrogrid.xmlutils.XmlValidatorIfc;
28
29 import org.astrogrid.xmlutils.XmlValidatorXercesImpl;
30
31
32
33 import java.util.Map;
34
35 import java.util.TreeMap;
36
37
38
39 /***
40
41 * <p>Command-line harness for XML Validation functionality.
42
43 * <ul>
44
45 * <li>Checks the syntax of the XML input file for validity.
46
47 * <li>Validates the XML input file against its relevant schema(s),
48
49 * which can either be specified in the <tt>xsi:schemaLocation</tt>
50
51 * attribute of the toplevel document element, or provided in
52
53 * a namespace map.
54
55 * </ul>
56
57 *
58
59 * <p>If validation is successful, produces no output. If validation
60
61 * fails, an exception reports the validation error encountered.
62
63 *
64
65 * <p>Usage: java org.astrogrid.xmlutils.Validate filename.xml
66
67 *
68
69 * <p>See XmlValidatorIfc documentation for usage example with a namespace
70
71 * map.
72
73 *
74
75 * <p>TO DO: <ul>
76
77 * <li>In schema-validation mode, the Xerces parser can produce pretty
78
79 * cryptic parse-error messages - is there an alternative parser we
80
81 * can use? XML4j seems not much better (v. similar to Xerces).
82
83 * </ul>
84
85 *
86
87 *
88
89 * @see org.astrogrid.xmlutils.XmlValidatorIfc
90
91 * @see org.astrogrid.xmlutils.XmlValidatorXercesImpl
92
93 *
94
95 *
96
97 * @author Kona Andrews,
98
99 * <a href="mailto:kea@ast.cam.ac.uk">kea@ast.cam.ac.uk</a>
100
101 * @version 1.0
102
103 *
104
105 *
106
107 * (c) Copyright Astrogrid 2002; all rights reserved.
108
109 * See http://www.astrogrid.org/code_licence.html for terms of usage.
110
111 */
112
113 public class Validate
114
115 {
116
117 /***
118
119 * Dummy constructor - does nothing.
120
121 */
122
123 public Validate()
124
125 {
126
127 }
128
129
130
131 /***
132
133 * Validates the XML file named in args[0] for syntactic
134
135 * correctness, and for semantic correctness against its
136
137 * schema (whic must be specified in the
138
139 * <tt>xsi:schemaLocation</tt> attribute of the toplevel
140
141 * document element.
142
143 */
144
145 public static void main(String [] args) throws Exception {
146
147
148
149 if (args.length != 1)
150
151 {
152
153
154
155 System.out.println("\nUSAGE: \n"
156
157 + "java org.astrogrid.xmlutils.Validate <inputXMLFile>\n");
158
159 }
160
161 else
162
163 {
164
165
166
167 XmlValidatorXercesImpl validator = new XmlValidatorXercesImpl();
168
169 validator.setFeature("ValidateSchema",true);
170
171 validator.setFeature("SuppressWarnings",false);
172
173 validator.setFeature("UseNamespaces",true);
174
175
176
177 validator.validate(args[0]);
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 }
222
223 }
224
225 }
226
227
228