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
|
---|
14 | task 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
|
---|
16 | SAX1/2 parser if needed.</p>
|
---|
17 |
|
---|
18 | <p>This task supports the use of nested
|
---|
19 | <li><a href="../CoreTypes/xmlcatalog.html"><tt><xmlcatalog></tt></a> elements</li>
|
---|
20 | <li><tt><dtd></tt> elements which are used to resolve DTDs and entities</li>
|
---|
21 | <li><tt><attribute></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><property></tt> elements, containing string properties
|
---|
26 | </p>
|
---|
27 |
|
---|
28 | <p><b>Warning</b> : JAXP creates by default a non namespace aware parser.
|
---|
29 | The <tt>"http://xml.org/sax/features/namespaces"</tt> feature is set
|
---|
30 | by default to <tt>false</tt> by the JAXP implementation used by ant. To validate
|
---|
31 | a document containing namespaces,
|
---|
32 | set the namespaces feature to <tt>true</tt> explicitly by nesting the following element:
|
---|
33 | <pre>
|
---|
34 | <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
---|
35 | </pre>
|
---|
36 | If you are using for instance a <tt>xsi:noNamespaceSchemaLocation</tt> attribute in your XML files,
|
---|
37 | you 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
|
---|
40 | may 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><classpath></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><dtd></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><xmlcatalog></tt></a>
|
---|
110 | element is used to perform entity resolution.</p>
|
---|
111 | <h4>attribute</h4>
|
---|
112 | <p>The <tt><attribute></tt> element is used to set parser features.<br>
|
---|
113 | Features usable with the xerces parser are defined here :
|
---|
114 | <a href="http://xml.apache.org/xerces-j/features.html">Setting features</a><br>
|
---|
115 |
|
---|
116 | SAX 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><property></tt> element is used to set properties.
|
---|
140 | These 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>
|
---|
142 | Properties 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 | <xmlvalidate file="toto.xml"/>
|
---|
167 | </pre>
|
---|
168 | Validate toto.xml
|
---|
169 | <pre>
|
---|
170 | <xmlvalidate failonerror="no" lenient="yes" warn="yes"
|
---|
171 | classname="org.apache.xerces.parsers.SAXParser">
|
---|
172 | classpath="lib/xerces.jar">
|
---|
173 | <fileset dir="src" includes="style/*.xsl"/>
|
---|
174 | </xmlvalidate>
|
---|
175 | </pre>
|
---|
176 | Validate all .xsl files in src/style, but only warn if there is an error, rather than
|
---|
177 | halt the build.
|
---|
178 | <pre>
|
---|
179 |
|
---|
180 | <xmlvalidate file="struts-config.xml" warn="false">
|
---|
181 | <dtd publicId="-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
|
---|
182 | location="struts-config_1_0.dtd"/>
|
---|
183 | </xmlvalidate>
|
---|
184 | </pre>
|
---|
185 |
|
---|
186 | Validate a struts configuration, using a local copy of the DTD.
|
---|
187 | <pre>
|
---|
188 | <xmlvalidate failonerror="no">
|
---|
189 | <fileset dir="${project.dir}" includes="**/*.xml"/>
|
---|
190 | <xmlcatalog refid="mycatalog"/>
|
---|
191 | </xmlvalidate>
|
---|
192 | </pre>
|
---|
193 |
|
---|
194 | Scan all XML files in the project, using a predefined catalog to map URIs to local files.
|
---|
195 | <pre>
|
---|
196 | <xmlvalidate failonerror="no">
|
---|
197 | <fileset dir="${project.dir}" includes="**/*.xml"/>
|
---|
198 | <xmlcatalog>
|
---|
199 | <dtd
|
---|
200 | publicId="-//ArielPartners//DTD XML Article V1.0//EN"
|
---|
201 | location="com/arielpartners/knowledgebase/dtd/article.dtd"/>
|
---|
202 | </xmlcatalog>
|
---|
203 | </xmlvalidate>
|
---|
204 | </pre>
|
---|
205 | Scan all XML files in the project, using the catalog defined inline.
|
---|
206 |
|
---|
207 | <pre>
|
---|
208 | <xmlvalidate failonerror="yes" lenient="no" warn="yes">
|
---|
209 | <fileset dir="xml" includes="**/*.xml"/>
|
---|
210 | <attribute name="http://xml.org/sax/features/validation" value="true"/>
|
---|
211 | <attribute name="http://apache.org/xml/features/validation/schema" value="true"/>
|
---|
212 | <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
---|
213 | </xmlvalidate>
|
---|
214 | </pre>
|
---|
215 | Validate 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 | <pathconvert dirsep="/" property="xsd.file">
|
---|
222 | <path>
|
---|
223 | <pathelement location="xml/doc.xsd"/>
|
---|
224 | </path>
|
---|
225 | </pathconvert>
|
---|
226 |
|
---|
227 | <xmlvalidate file="xml/endpiece-noSchema.xml" lenient="false"
|
---|
228 | failonerror="true" warn="true">
|
---|
229 | <attribute name="http://apache.org/xml/features/validation/schema"
|
---|
230 | value="true"/>
|
---|
231 | <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
---|
232 | <property
|
---|
233 | name="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
|
---|
234 | value="${xsd.file}"/>
|
---|
235 | </xmlvalidate>
|
---|
236 | </pre>
|
---|
237 | <br>
|
---|
238 | Validate the file xml/endpiece-noSchema.xml against the schema xml/doc.xsd.
|
---|
239 | <br>
|
---|
240 | <hr>
|
---|
241 | <p align="center">Copyright © 2001-2002,2004 The Apache Software Foundation. All rights
|
---|
242 | Reserved.</p>
|
---|
243 |
|
---|
244 | </body>
|
---|
245 | </html>
|
---|
246 |
|
---|