1 | <!--
|
---|
2 | Licensed to the Apache Software Foundation (ASF) under one or more
|
---|
3 | contributor license agreements. See the NOTICE file distributed with
|
---|
4 | this work for additional information regarding copyright ownership.
|
---|
5 | The ASF licenses this file to You under the Apache License, Version 2.0
|
---|
6 | (the "License"); you may not use this file except in compliance with
|
---|
7 | the License. You may obtain a copy of the License at
|
---|
8 |
|
---|
9 | http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 |
|
---|
11 | Unless required by applicable law or agreed to in writing, software
|
---|
12 | distributed under the License is distributed on an "AS IS" BASIS,
|
---|
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
14 | See the License for the specific language governing permissions and
|
---|
15 | limitations under the License.
|
---|
16 | -->
|
---|
17 | <html>
|
---|
18 |
|
---|
19 | <head>
|
---|
20 | <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
|
---|
21 | <title>XMLValidate Task</title>
|
---|
22 | </head>
|
---|
23 |
|
---|
24 | <body>
|
---|
25 |
|
---|
26 | <h2><a name="xmlvalidate">XMLValidate</a></h2>
|
---|
27 | <h3>Description</h3>
|
---|
28 |
|
---|
29 | <p>This task checks that XML files are valid (or only well formed). The
|
---|
30 | task uses the SAX2 parser implementation provided by JAXP by default
|
---|
31 | (probably the one that is used by Ant itself), but one can specify any
|
---|
32 | SAX1/2 parser if needed.</p>
|
---|
33 |
|
---|
34 | <p>This task supports the use of nested
|
---|
35 | <li><a href="../CoreTypes/xmlcatalog.html"><tt><xmlcatalog></tt></a> elements</li>
|
---|
36 | <li><tt><dtd></tt> elements which are used to resolve DTDs and entities</li>
|
---|
37 | <li><tt><attribute></tt> elements which are used to set features on the parser.
|
---|
38 | These can be any number of
|
---|
39 | <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"><tt>http://xml.org/sax/features/</tt></a>
|
---|
40 | or other features that your parser may support.</li>
|
---|
41 | <li><tt><property></tt> elements, containing string properties
|
---|
42 | </p>
|
---|
43 |
|
---|
44 | <p><b>Warning</b> : JAXP creates by default a non namespace aware parser.
|
---|
45 | The <tt>"http://xml.org/sax/features/namespaces"</tt> feature is set
|
---|
46 | by default to <tt>false</tt> by the JAXP implementation used by ant. To validate
|
---|
47 | a document containing namespaces,
|
---|
48 | set the namespaces feature to <tt>true</tt> explicitly by nesting the following element:
|
---|
49 | <pre>
|
---|
50 | <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
---|
51 | </pre>
|
---|
52 | If you are using for instance a <tt>xsi:noNamespaceSchemaLocation</tt> attribute in your XML files,
|
---|
53 | you will need this namespace support feature.
|
---|
54 | </p>
|
---|
55 | <p>If you are using a parser not generated by JAXP, by using the <tt>classname</tt> attribute of xmlvalidate, this warning
|
---|
56 | may not apply.</p>
|
---|
57 |
|
---|
58 |
|
---|
59 | <h3>Parameters</h3>
|
---|
60 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
61 | <tr>
|
---|
62 | <td valign="top"><b>Attribute</b></td>
|
---|
63 | <td valign="top"><b>Description</b></td>
|
---|
64 | <td align="center" valign="top"><b>Required</b></td>
|
---|
65 | </tr>
|
---|
66 | <tr>
|
---|
67 | <td valign="top">file</td>
|
---|
68 | <td valign="top">the file(s) you want to check. (optionally can use an embedded fileset)</td>
|
---|
69 | <td valign="top" align="center">No</td>
|
---|
70 | </tr>
|
---|
71 | <tr>
|
---|
72 | <td valign="top">lenient</td>
|
---|
73 | <td valign="top">
|
---|
74 | if true, only check the XML document is well formed
|
---|
75 | (ignored if the specified parser is a SAX1 parser)
|
---|
76 | </td>
|
---|
77 | <td valign="top" align="center">No</td>
|
---|
78 | </tr>
|
---|
79 | <tr>
|
---|
80 | <td valign="top">classname</td>
|
---|
81 | <td valign="top">the parser to use.</td>
|
---|
82 | <td align="center" valign="top">No</td>
|
---|
83 | </tr>
|
---|
84 | <tr>
|
---|
85 | <td valign="top">classpathref</td>
|
---|
86 | <td valign="top">where to find the parser class. Optionally can use an embedded <tt><classpath></tt> element.</td>
|
---|
87 | <td align="center" valign="top">No</td>
|
---|
88 | </tr>
|
---|
89 | <tr>
|
---|
90 | <td valign="top">failonerror</td>
|
---|
91 | <td valign="top">fails on a error if set to true (defaults to true).</td>
|
---|
92 | <td align="center" valign="top">No</td>
|
---|
93 | </tr>
|
---|
94 | <tr>
|
---|
95 | <td valign="top">warn</td>
|
---|
96 | <td valign="top">log parser warn events.</td>
|
---|
97 | <td align="center" valign="top">No</td>
|
---|
98 | </tr>
|
---|
99 | </table>
|
---|
100 |
|
---|
101 | <h3><a name="nested">Nested Elements</a></h3>
|
---|
102 | <h4>dtd</h4>
|
---|
103 | <p>
|
---|
104 | <tt><dtd></tt> is used to specify different locations for DTD resolution.
|
---|
105 | </p>
|
---|
106 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
107 | <tr>
|
---|
108 | <td width="12%" valign="top"><b>Attribute</b></td>
|
---|
109 | <td width="78%" valign="top"><b>Description</b></td>
|
---|
110 | <td width="10%" valign="top"><b>Required</b></td>
|
---|
111 | </tr>
|
---|
112 | <tr>
|
---|
113 | <td valign="top">publicId</td>
|
---|
114 | <td valign="top">Public ID of the DTD to resolve</td>
|
---|
115 | <td align="center" valign="top">Yes</td>
|
---|
116 | </tr>
|
---|
117 | <tr>
|
---|
118 | <td valign="top">location</td>
|
---|
119 | <td valign="top">Location of the DTD to use, which can be a file,
|
---|
120 | a resource, or a URL</td>
|
---|
121 | <td align="center" valign="top">Yes</td>
|
---|
122 | </tr>
|
---|
123 | </table>
|
---|
124 | <h4>xmlcatalog</h4>
|
---|
125 | <p>The <a href="../CoreTypes/xmlcatalog.html"><tt><xmlcatalog></tt></a>
|
---|
126 | element is used to perform entity resolution.</p>
|
---|
127 | <h4>attribute</h4>
|
---|
128 | <p>The <tt><attribute></tt> element is used to set parser features.<br>
|
---|
129 | Features usable with the xerces parser are defined here :
|
---|
130 | <a href="http://xml.apache.org/xerces-j/features.html">Setting features</a><br>
|
---|
131 |
|
---|
132 | SAX features are defined here:
|
---|
133 | <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"><tt>http://xml.org/sax/features/</tt></a><br>
|
---|
134 | </p>
|
---|
135 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
136 | <tr>
|
---|
137 | <td width="12%" valign="top"><b>Attribute</b></td>
|
---|
138 | <td width="78%" valign="top"><b>Description</b></td>
|
---|
139 | <td width="10%" valign="top"><b>Required</b></td>
|
---|
140 | </tr>
|
---|
141 | <tr>
|
---|
142 | <td valign="top">name</td>
|
---|
143 | <td valign="top">The name of the feature</td>
|
---|
144 | <td align="center" valign="top">Yes</td>
|
---|
145 | </tr>
|
---|
146 | <tr>
|
---|
147 | <td valign="top">value</td>
|
---|
148 | <td valign="top">The boolean value of the feature</td>
|
---|
149 | <td align="center" valign="top">Yes</td>
|
---|
150 | </tr>
|
---|
151 | </table>
|
---|
152 | </p>
|
---|
153 |
|
---|
154 | <h4>property</h4>
|
---|
155 | <p>The <tt><property></tt> element is used to set properties.
|
---|
156 | These properties are defined here for the xerces XML parser implementation :
|
---|
157 | <a href="http://xml.apache.org/xerces-j/properties.html">XML Parser properties</a>
|
---|
158 | Properties can be used to set the schema used to validate the XML file.
|
---|
159 | </p>
|
---|
160 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
161 | <tr>
|
---|
162 | <td width="12%" valign="top"><b>Attribute</b></td>
|
---|
163 | <td width="78%" valign="top"><b>Description</b></td>
|
---|
164 | <td width="10%" valign="top"><b>Required</b></td>
|
---|
165 | </tr>
|
---|
166 | <tr>
|
---|
167 | <td valign="top">name</td>
|
---|
168 | <td valign="top">The name of the feature</td>
|
---|
169 | <td align="center" valign="top">Yes</td>
|
---|
170 | </tr>
|
---|
171 | <tr>
|
---|
172 | <td valign="top">value</td>
|
---|
173 | <td valign="top">The string value of the property</td>
|
---|
174 | <td align="center" valign="top">Yes</td>
|
---|
175 | </tr>
|
---|
176 | </table>
|
---|
177 | </p>
|
---|
178 |
|
---|
179 |
|
---|
180 | <h3>Examples</h3>
|
---|
181 | <pre>
|
---|
182 | <xmlvalidate file="toto.xml"/>
|
---|
183 | </pre>
|
---|
184 | Validate toto.xml
|
---|
185 | <pre>
|
---|
186 | <xmlvalidate failonerror="no" lenient="yes" warn="yes"
|
---|
187 | classname="org.apache.xerces.parsers.SAXParser">
|
---|
188 | classpath="lib/xerces.jar">
|
---|
189 | <fileset dir="src" includes="style/*.xsl"/>
|
---|
190 | </xmlvalidate>
|
---|
191 | </pre>
|
---|
192 | Validate all .xsl files in src/style, but only warn if there is an error, rather than
|
---|
193 | halt the build.
|
---|
194 | <pre>
|
---|
195 |
|
---|
196 | <xmlvalidate file="struts-config.xml" warn="false">
|
---|
197 | <dtd publicId="-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
|
---|
198 | location="struts-config_1_0.dtd"/>
|
---|
199 | </xmlvalidate>
|
---|
200 | </pre>
|
---|
201 |
|
---|
202 | Validate a struts configuration, using a local copy of the DTD.
|
---|
203 | <pre>
|
---|
204 | <xmlvalidate failonerror="no">
|
---|
205 | <fileset dir="${project.dir}" includes="**/*.xml"/>
|
---|
206 | <xmlcatalog refid="mycatalog"/>
|
---|
207 | </xmlvalidate>
|
---|
208 | </pre>
|
---|
209 |
|
---|
210 | Scan all XML files in the project, using a predefined catalog to map URIs to local files.
|
---|
211 | <pre>
|
---|
212 | <xmlvalidate failonerror="no">
|
---|
213 | <fileset dir="${project.dir}" includes="**/*.xml"/>
|
---|
214 | <xmlcatalog>
|
---|
215 | <dtd
|
---|
216 | publicId="-//ArielPartners//DTD XML Article V1.0//EN"
|
---|
217 | location="com/arielpartners/knowledgebase/dtd/article.dtd"/>
|
---|
218 | </xmlcatalog>
|
---|
219 | </xmlvalidate>
|
---|
220 | </pre>
|
---|
221 | Scan all XML files in the project, using the catalog defined inline.
|
---|
222 |
|
---|
223 | <pre>
|
---|
224 | <xmlvalidate failonerror="yes" lenient="no" warn="yes">
|
---|
225 | <fileset dir="xml" includes="**/*.xml"/>
|
---|
226 | <attribute name="http://xml.org/sax/features/validation" value="true"/>
|
---|
227 | <attribute name="http://apache.org/xml/features/validation/schema" value="true"/>
|
---|
228 | <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
---|
229 | </xmlvalidate>
|
---|
230 | </pre>
|
---|
231 | Validate all .xml files in xml directory with the parser configured to perform XSD validation.
|
---|
232 | Note: The parser must support the feature
|
---|
233 | <code>http://apache.org/xml/features/validation/schema</code>.
|
---|
234 | The <a href="schemavalidate.html">schemavalidate</a> task is better for validating
|
---|
235 | W3C XML Schemas, as it extends this task with the right options automatically enabled,
|
---|
236 | and makes it easy to add a list of schema files/URLs to act as sources.
|
---|
237 |
|
---|
238 | <pre>
|
---|
239 | <!-- Converts path to URL format -->
|
---|
240 | <pathconvert dirsep="/" property="xsd.file">
|
---|
241 | <path>
|
---|
242 | <pathelement location="xml/doc.xsd"/>
|
---|
243 | </path>
|
---|
244 | </pathconvert>
|
---|
245 |
|
---|
246 | <xmlvalidate file="xml/endpiece-noSchema.xml" lenient="false"
|
---|
247 | failonerror="true" warn="true">
|
---|
248 | <attribute name="http://apache.org/xml/features/validation/schema"
|
---|
249 | value="true"/>
|
---|
250 | <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
---|
251 | <property
|
---|
252 | name="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
|
---|
253 | value="${xsd.file}"/>
|
---|
254 | </xmlvalidate>
|
---|
255 | </pre>
|
---|
256 | <br>
|
---|
257 | Validate the file xml/endpiece-noSchema.xml against the schema xml/doc.xsd.
|
---|
258 | <br>
|
---|
259 |
|
---|
260 |
|
---|
261 | </body>
|
---|
262 | </html>
|
---|
263 |
|
---|