Introduction
52 |53 | XmlValidate is a quick & flexible XML validator capable of performing bulk 54 | validation of XML documents against XML Schemas 55 | as defined in the XML documents or forcing another schema target. 56 |
57 |58 |
59 | XmlValidate validates individual XML documents by filename or URL 60 | or recursively searching directories with a list of target file 61 | extensions. First documents are checked as being well-formed XML. 62 | If parsing XML with non-validating parser fails then validation for that 63 | file stops. 64 |
65 |66 |
67 | Here are three ways to validate XML documents using XmlValidate: 68 |
69 |70 | 71 |
-
72 |
-
73 |
74 | The -map option maps schema namespaces to given target schema locations. 75 | It rewrites XML with location of schema instance document then validates against 76 | target schema. If schema namespace is not found then it does not validate 77 | the document. This validates the document against the actual schema namespace 78 | defined in the document as opposed to the other approaches that rewrite 79 | the XML documents to any target schema. 80 |
81 |82 | old: <kml xmlns="http://earth.google.com/kml/2.1"> 83 | 84 | new: <kml xmlns="http://earth.google.com/kml/2.1" 85 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 86 | xsi:schemaLocation="http://earth.google.com/kml/2.1 file:/C:/xml/kml21.xsd"> 87 |
88 |Note if root element is "kml" and no namespace is specified then KML 2.0 namespace is used to validate document.
89 |
90 |
91 | -
92 |
93 | Specifing a schema without a namespace implies noNamespaceSchemaLocation 94 | attribute should be added to all XML documents and validate against that schema. 95 |
96 |97 | no namespace schema: 98 | 99 | <event xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 100 | xsi:noNamespaceSchemaLocation="C:/cot/schema/Event.xsd"> 101 |
102 |
103 |
104 | -
105 |
106 | And finally specify -ns and -schema options to provide a target namespace URI 107 | and schema location. All XML documents specified in search location(s) 108 | will be rewritten and the target schemaLocation will be used regardless 109 | of the default namespace of that document. So for example KML 2.1 documents 110 | can be validated against the 2.2 schema, and vice versa. 111 |
112 |113 | old: <kml xmlns="http://earth.google.com/kml/2.1"> 114 | 115 | new: <kml xmlns="http://www.opengis.net/kml/2.2" 116 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 117 | xsi:schemaLocation="http://www.opengis.net/kml/2.2 file:/C:/xml/kml22.xsd"> 118 |
119 |
120 |
123 | Note that XML is reformatted so errors/warnings with line/column numbers are respect to 124 | the reformatted content not the original so context is printed at that line/column number 125 | after each error in order that errors can be tracked down and corrected in original 126 | XML document. If you want the reformatted XML document printed then use -dump mode. 127 | If the error is in the XML Schema not the instance document then the context will not be printed. 128 |
129 | 130 |Contents
131 |This distribution contains the following files: 132 |
| README.html | 135 |This documentation file | 136 |
| ns.map | 139 |Namespace mapping file associated with provided schemas used with -map option | 140 |
| build.gradle | 143 |Gradle build file | 144 |
Installation
149 |150 | This standalone Java application requires a Java Runtime Environment (JRE) installation of version 1.6 or later. 151 |
152 |
153 |
154 | Type: ./gradlew clean test install
155 |
156 | Downloaded files (including the Gradle distribution itself) will be stored in the Gradle user home directory (typically "
159 |
160 | XmlValidate is pre-loaded with a number of common XML schemas (KML, GPX).
161 | To install this application, copy the xmlValidate folder along with the batch files
162 | [ bin/kml21.bat + bin/kml22.bat + bin/xv.bat ]. Next edit ns.map file to add new XML schemas to validate
163 | other XML documents. XML Schemas can be added by URL, absolute path, or add to schemas folder and prefix schema with
164 | ${XV_HOME}.
165 |
Usage
168 |169 |
170 | Usage: XmlValidate [options] [-map=file] | [-schema=file (-ns=uri)] <xml-document file, URL, or directory...> 171 |172 | 173 |
174 | Options: 175 | 176 |
| -map=<schema-property-file> | Schema map properties: namespace to file/URL mappings. 179 | Note if root element is "kml" and no namespace is specified then KML 2.0 namespace is used. 180 | |
| -schema=<path-to-xml-schema> | Set target schema location (file path or URL). 183 | If validating many XML documents recommend make local copies of XML Schemas and refer to the local 184 | file name rather than having to fetch Schema by URL for each document. 185 | |
| -schemaLocation=<namespace=location> | Add explicit namespace with target schema location (file path or URL). 189 | This will appear in the xsi:schemaLocation element if the target namespace is referenced in the XML document. 190 | |
| -ns=<schemaLocation-namespace> | Set namespace defined in schemaLocation attribute (e.g. http://earth.google.com/kml/2.1) 194 | Without setting this the target schema is assumed to have no namespace and noNamespaceSchemaLocation 195 | attribute is declared in XML instances. 196 | |
| -dump[=n] |
200 | Print reformatted XML documents based on dump level:
201 | 0: no output [default], 202 | 1: print KML on errors only, 203 | 2: print all inputs 204 | If number not specified with -dump argument then 1 is assumed otherwise 0 205 | if -dump argument is not used. 206 | Note the line and column numbers in errors are with respect to these formatted XML documents. 207 | |
| -maxdump=n | Set max length (in bytes) of XML output used for each document in dump. 211 | |
| -K | KML mode for extra KML validation. 215 | |
| -Z | KMZ mode checks and validates all kml files inside KMZ files. 219 | Default mode only checks the first kml file. 220 | |
| -kml | Validate .kml files only (default=xml) This overrides and replaces 224 | the default XML target with KML when searching for files in directories. 225 | |
| -kmz | Validate .kml and .kmz files only (default=xml) This overrides and replaces 228 | the default XML target with KML amnd KMZ when searching for files in directories. 229 | |
| -x=ExtensionList | Add additional file extensions to list (default=xml) 232 | extensions separated by ':' (e.g. -x=gpx:x3d:svg) 233 | |
| -S | 237 |Enable summary mode to only show the final total counts (default=false). 238 | This is helpful when validating large collection of files where output would be huge. 239 | |
| Enable verbose mode (default=false). 243 | | -v[=true] | 244 |
| -debug | 247 |Enable debug mode to print exception stack traces (default=false). | 248 |
-
254 |
-
255 | To check all .kml files against target KML 2.2 schema regardless of default schema used:
256 |
257 | xv -kml -schema=C:/pathToXsd/kml22.xsd -ns=http://www.opengis.net/kml/2.2 C:/pathToMyKmlFiles 258 |
259 |
260 | -
261 | To check all CoT .xml files against CoT Schema:
262 |
263 | xv -schema=C:/pathToXsd/event.xsd C:/pathToData/cot.xml 264 |
265 |
266 | -
267 | To check kml and kmz files against local schemas as defined in KML files:
268 |
269 | xv -map=ns.map C:/pathToMyKmlFiles 270 |
271 |
272 | -
273 | Validate by URL for KML and target schema and print KML content
274 | if any errors are found but limit size of each file printed to first 4K: 275 |276 | xv -dump -maxDump=4096 -ns=http://earth.google.com/kml/2.1 277 | -schema=http://code.google.com/apis/kml/schema/kml21.xsd 278 | http://kml-samples.googlecode.com/svn/trunk/kml/kmz/simple/big.kmz 279 |
280 |
281 | -
282 | Validate by XML document with explicit schema location
283 |284 | xv -schemaLocation=http://myExtension=ext.xsd example.xml 285 |
286 |
287 |
289 | Note: xv command in examples above is a short-cut to the executable 290 | command using java and XmlValidate.jar on the CLASSPATH or by using the equivalent batch file/shell script. 291 | See xv.bat, kml21.bat, and kml22.bat for example usage. 292 |293 | 294 |
Release History
295 |296 |
| Version | 299 |Release date | 300 |Description | 301 |
|---|---|---|
| 1.0.2 | 305 |07/01/14 | 306 |
|
313 |
| 1.0.1 | 317 |11/14/13 | 318 |
|
322 |
| 1.0.0 | 326 |04/27/12 | 327 |
|
331 |
| 0.4.2 | 335 |03/23/11 | 336 |
|
343 |
| 0.4.1 | 347 |08/23/10 | 348 |
|
352 |
| 0.4.0 | 356 |03/23/09 | 357 |
|
365 |
| 0.3.0 | 369 |02/13/09 | 370 |
|
378 |
| 0.2.0 | 382 |02/01/09 | 383 |
|
391 |
| 0.1.0 | 395 |04/17/08 | 396 |
|
401 |