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