source: release-kits/lirk3/bin/ant-installer/web/manual1.7.0/manual/OptionalTasks/xmlvalidate.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 9.4 KB
Line 
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
30task 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
32SAX1/2 parser if needed.</p>
33
34<p>This task supports the use of nested
35 <li><a href="../CoreTypes/xmlcatalog.html"><tt>&lt;xmlcatalog&gt;</tt></a> elements</li>
36 <li><tt>&lt;dtd&gt;</tt> elements which are used to resolve DTDs and entities</li>
37 <li><tt>&lt;attribute&gt;</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>&lt;property&gt;</tt> elements, containing string properties
42</p>
43
44<p><b>Warning</b> : JAXP creates by default a non namespace aware parser.
45The <tt>"http://xml.org/sax/features/namespaces"</tt> feature is set
46by default to <tt>false</tt> by the JAXP implementation used by ant. To validate
47a document containing namespaces,
48set the namespaces feature to <tt>true</tt> explicitly by nesting the following element:
49<pre>
50 &lt;attribute name="http://xml.org/sax/features/namespaces" value="true"/&gt;
51</pre>
52If you are using for instance a <tt>xsi:noNamespaceSchemaLocation</tt> attribute in your XML files,
53you 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
56may 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>&lt;classpath&gt;</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>&lt;dtd&gt;</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>&lt;xmlcatalog&gt;</tt></a>
126element is used to perform entity resolution.</p>
127<h4>attribute</h4>
128<p>The <tt>&lt;attribute&gt;</tt> element is used to set parser features.<br>
129Features usable with the xerces parser are defined here :
130 <a href="http://xml.apache.org/xerces-j/features.html">Setting features</a><br>
131
132SAX 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>&lt;property&gt;</tt> element is used to set properties.
156These 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>
158Properties 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&lt;xmlvalidate file="toto.xml"/&gt;
183</pre>
184Validate toto.xml
185<pre>
186&lt;xmlvalidate failonerror="no" lenient="yes" warn="yes"
187 classname="org.apache.xerces.parsers.SAXParser"&gt;
188 classpath="lib/xerces.jar"&gt;
189 &lt;fileset dir="src" includes="style/*.xsl"/&gt;
190&lt;/xmlvalidate&gt;
191</pre>
192Validate all .xsl files in src/style, but only warn if there is an error, rather than
193halt the build.
194<pre>
195
196&lt;xmlvalidate file="struts-config.xml" warn="false"&gt;
197 &lt;dtd publicId="-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
198 location="struts-config_1_0.dtd"/&gt;
199&lt;/xmlvalidate&gt;
200</pre>
201
202Validate a struts configuration, using a local copy of the DTD.
203<pre>
204&lt;xmlvalidate failonerror="no"&gt;
205 &lt;fileset dir="${project.dir}" includes="**/*.xml"/&gt;
206 &lt;xmlcatalog refid="mycatalog"/&gt;
207&lt;/xmlvalidate&gt;
208</pre>
209
210Scan all XML files in the project, using a predefined catalog to map URIs to local files.
211<pre>
212&lt;xmlvalidate failonerror="no"&gt;
213 &lt;fileset dir="${project.dir}" includes="**/*.xml"/&gt;
214 &lt;xmlcatalog&gt;
215 &lt;dtd
216 publicId=&quot;-//ArielPartners//DTD XML Article V1.0//EN&quot;
217 location=&quot;com/arielpartners/knowledgebase/dtd/article.dtd&quot;/&gt;
218 &lt;/xmlcatalog&gt;
219&lt;/xmlvalidate&gt;
220</pre>
221Scan all XML files in the project, using the catalog defined inline.
222
223<pre>
224&lt;xmlvalidate failonerror="yes" lenient="no" warn="yes"&gt;
225 &lt;fileset dir="xml" includes="**/*.xml"/&gt;
226 &lt;attribute name="http://xml.org/sax/features/validation" value="true"/&gt;
227 &lt;attribute name="http://apache.org/xml/features/validation/schema" value="true"/&gt;
228 &lt;attribute name="http://xml.org/sax/features/namespaces" value="true"/&gt;
229&lt;/xmlvalidate&gt;
230</pre>
231Validate all .xml files in xml directory with the parser configured to perform XSD validation.
232Note: The parser must support the feature
233<code>http://apache.org/xml/features/validation/schema</code>.
234The <a href="schemavalidate.html">schemavalidate</a> task is better for validating
235W3C XML Schemas, as it extends this task with the right options automatically enabled,
236and 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&lt;pathconvert dirsep="/" property="xsd.file"&gt;
241&lt;path&gt;
242 &lt;pathelement location="xml/doc.xsd"/&gt;
243&lt;/path&gt;
244&lt;/pathconvert&gt;
245
246&lt;xmlvalidate file="xml/endpiece-noSchema.xml" lenient="false"
247 failonerror="true" warn="true"&gt;
248 &lt;attribute name="http://apache.org/xml/features/validation/schema"
249 value="true"/&gt;
250 &lt;attribute name="http://xml.org/sax/features/namespaces" value="true"/&gt;
251 &lt;property
252 name="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
253 value="${xsd.file}"/&gt;
254&lt;/xmlvalidate&gt;
255</pre>
256<br>
257Validate the file xml/endpiece-noSchema.xml against the schema xml/doc.xsd.
258<br>
259
260
261</body>
262</html>
263
Note: See TracBrowser for help on using the repository browser.