2006-09-11 04:19:00 +00:00
|
|
|
<!--
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
-->
|
2001-04-10 04:47:00 +00:00
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
2005-04-29 18:58:16 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
|
2001-04-10 04:47:00 +00:00
|
|
|
<title>XMLValidate Task</title>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
2018-01-22 23:52:21 +01:00
|
|
|
<h2 id="xmlvalidate">XMLValidate</h2>
|
2001-04-10 04:47:00 +00:00
|
|
|
<h3>Description</h3>
|
2002-04-22 08:56:13 +00:00
|
|
|
|
2018-02-28 07:58:59 +01:00
|
|
|
<p>This task checks that XML files are valid (or only well formed). The task uses the SAX2 parser
|
|
|
|
implementation provided by JAXP by default (probably the one that is used by Apache Ant itself), but
|
|
|
|
one can specify any SAX1/2 parser if needed.</p>
|
2001-04-10 04:47:00 +00:00
|
|
|
|
2018-01-22 23:52:21 +01:00
|
|
|
<p>This task supports the use of nested</p>
|
|
|
|
<ul>
|
2018-02-28 07:58:59 +01:00
|
|
|
<li><a href="../Types/xmlcatalog.html"><code><xmlcatalog></code></a> elements</li>
|
|
|
|
<li><code><dtd></code> elements which are used to resolve DTDs and entities</li>
|
|
|
|
<li><code><attribute></code> elements which are used to set features on the parser. These
|
|
|
|
can be any number
|
2018-03-08 07:43:53 +01:00
|
|
|
of <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"
|
|
|
|
target="_top"><code>http://xml.org/sax/features/</code></a> or other features that your parser
|
|
|
|
may support.</li>
|
2018-02-28 07:58:59 +01:00
|
|
|
<li><code><property></code> elements, containing string properties</li>
|
2018-01-22 23:52:21 +01:00
|
|
|
</ul>
|
2002-06-01 12:26:43 +00:00
|
|
|
|
2018-02-28 07:58:59 +01:00
|
|
|
<p><strong>Warning</strong>: By default, JAXP creates a non namespace aware parser.
|
|
|
|
The <var>http://xml.org/sax/features/namespaces</var> feature is set by default to <q>false</q> by
|
|
|
|
the JAXP implementation used by Ant. To validate a document containing namespaces, set the
|
|
|
|
namespaces feature to <q>true</q> explicitly by nesting the following element:</p>
|
|
|
|
<pre><attribute name="http://xml.org/sax/features/namespaces" value="true"/></pre>
|
|
|
|
<p>If you are using for instance a <code>xsi:noNamespaceSchemaLocation</code> attribute in your XML
|
|
|
|
files, you will need this namespace support feature.</p>
|
|
|
|
<p>If you are using a parser not generated by JAXP, by using the <var>classname</var> attribute
|
|
|
|
of <code>xmlvalidate</code>, this warning may not apply.</p>
|
2004-06-11 22:47:23 +00:00
|
|
|
|
2001-04-10 04:47:00 +00:00
|
|
|
<h3>Parameters</h3>
|
2018-02-28 07:58:59 +01:00
|
|
|
<table class="attr">
|
2001-04-10 04:47:00 +00:00
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<th>Attribute</th>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Required</th>
|
2001-04-10 04:47:00 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>file</td>
|
|
|
|
<td>the file(s) you want to check.</td>
|
|
|
|
<td>Yes, unless an embedded <code><fileset></code> is specified</td>
|
2001-04-10 04:47:00 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>lenient</td>
|
|
|
|
<td>if <q>true</q>, only check the XML document is well formed (ignored if the specified parser
|
|
|
|
is a SAX1 parser).</td>
|
|
|
|
<td>No</td>
|
2001-04-10 04:47:00 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>classname</td>
|
|
|
|
<td>the parser to use.</td>
|
|
|
|
<td>No</td>
|
2001-04-10 04:47:00 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>classpathref</td>
|
|
|
|
<td>where to find the parser class.</td>
|
|
|
|
<td>No, can use an embedded <code><classpath></code> element</td>
|
2001-04-10 04:47:00 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>failonerror</td>
|
|
|
|
<td>fails on a error if set to <q>true</q>.</td>
|
|
|
|
<td>No; defaults to <q>true</q></td>
|
2001-04-10 04:47:00 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>warn</td>
|
|
|
|
<td>log parser warn events.</td>
|
|
|
|
<td>No</td>
|
2001-04-10 04:47:00 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
2002-01-19 21:19:42 +00:00
|
|
|
|
2018-03-05 17:35:30 +01:00
|
|
|
<h3 id="nested">Parameters specified as nested elements</h3>
|
2002-01-19 21:19:42 +00:00
|
|
|
<h4>dtd</h4>
|
2018-02-28 07:58:59 +01:00
|
|
|
<p><code><dtd></code> is used to specify different locations for DTD resolution.</p>
|
|
|
|
<table class="attr">
|
2002-01-19 21:19:42 +00:00
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<th>Attribute</th>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Required</th>
|
2002-01-19 21:19:42 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>publicId</td>
|
|
|
|
<td>Public ID of the DTD to resolve</td>
|
|
|
|
<td>Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>location</td>
|
|
|
|
<td>Location of the DTD to use, which can be a file, a resource, or a URL</td>
|
|
|
|
<td>Yes</td>
|
2002-01-19 21:19:42 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
2002-06-01 12:26:43 +00:00
|
|
|
<h4>xmlcatalog</h4>
|
2018-02-28 07:58:59 +01:00
|
|
|
<p>The <a href="../Types/xmlcatalog.html"><code><xmlcatalog></code></a> element is used to
|
|
|
|
perform entity resolution.</p>
|
2002-09-23 14:59:42 +00:00
|
|
|
<h4>attribute</h4>
|
2018-02-28 07:58:59 +01:00
|
|
|
<p>The <code><attribute></code> element is used to set parser features.</p>
|
|
|
|
<p>Features usable with the Xerces parser are defined
|
2018-03-10 20:17:33 +01:00
|
|
|
here: <a href="https://xml.apache.org/xerces-j/features.html" target="_top">Setting Features</a></p>
|
2018-02-28 07:58:59 +01:00
|
|
|
<p>SAX features are defined
|
2018-03-08 07:43:53 +01:00
|
|
|
here: <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"
|
2018-03-10 20:17:33 +01:00
|
|
|
target="_top">SAX2 Standard Feature Flags</a></p>
|
2018-02-28 07:58:59 +01:00
|
|
|
<table class="attr">
|
2002-09-23 14:59:42 +00:00
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<th>Attribute</th>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Required</th>
|
2002-09-23 14:59:42 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>name</td>
|
|
|
|
<td>The name of the feature</td>
|
|
|
|
<td>Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>value</td>
|
|
|
|
<td>The boolean value of the feature</td>
|
|
|
|
<td>Yes</td>
|
2002-09-23 14:59:42 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
2002-01-19 21:19:42 +00:00
|
|
|
|
2004-06-11 15:29:27 +00:00
|
|
|
<h4>property</h4>
|
2018-02-28 07:58:59 +01:00
|
|
|
<p>The <code><property></code> element is used to set properties. These properties are
|
|
|
|
defined here for the Xerces XML parser
|
2018-03-08 07:43:53 +01:00
|
|
|
implementation: <a href="https://xml.apache.org/xerces-j/properties.html" target="_top">XML Parser
|
|
|
|
properties</a>. Properties can be used to set the schema used to validate the XML file.</p>
|
2018-02-28 07:58:59 +01:00
|
|
|
<table class="attr">
|
|
|
|
<tr>
|
|
|
|
<th>Attribute</th>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Required</th>
|
|
|
|
</tr>
|
2004-06-11 15:29:27 +00:00
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>name</td>
|
|
|
|
<td>The name of the feature</td>
|
|
|
|
<td>Yes</td>
|
2004-06-11 15:29:27 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2018-02-28 07:58:59 +01:00
|
|
|
<td>value</td>
|
|
|
|
<td>The string value of the property</td>
|
|
|
|
<td>Yes</td>
|
2004-06-11 15:29:27 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
2002-01-19 21:19:42 +00:00
|
|
|
|
2001-04-10 04:47:00 +00:00
|
|
|
<h3>Examples</h3>
|
2018-02-28 07:58:59 +01:00
|
|
|
<pre><xmlvalidate file="toto.xml"/></pre>
|
|
|
|
<p>Validate <samp>toto.xml</samp></p>
|
2002-09-09 16:49:23 +00:00
|
|
|
<pre>
|
2002-01-19 21:19:42 +00:00
|
|
|
<xmlvalidate failonerror="no" lenient="yes" warn="yes"
|
2002-09-04 11:05:19 +00:00
|
|
|
classname="org.apache.xerces.parsers.SAXParser">
|
2002-01-19 21:19:42 +00:00
|
|
|
classpath="lib/xerces.jar">
|
2002-07-09 21:06:15 +00:00
|
|
|
<fileset dir="src" includes="style/*.xsl"/>
|
2018-02-28 07:58:59 +01:00
|
|
|
</xmlvalidate></pre>
|
|
|
|
<p>Validate all <samp>.xsl</samp> files in <samp>src/style</samp>, but only warn if there is an
|
|
|
|
error, rather than halt the build.</p>
|
2002-09-09 02:50:35 +00:00
|
|
|
<pre>
|
2002-01-19 21:19:42 +00:00
|
|
|
<xmlvalidate file="struts-config.xml" warn="false">
|
|
|
|
<dtd publicId="-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
|
|
|
|
location="struts-config_1_0.dtd"/>
|
2018-02-28 07:58:59 +01:00
|
|
|
</xmlvalidate></pre>
|
2002-09-09 02:50:35 +00:00
|
|
|
|
2018-02-28 07:58:59 +01:00
|
|
|
<p>Validate a struts configuration, using a local copy of the DTD.</p>
|
2018-01-22 23:52:21 +01:00
|
|
|
<pre>
|
2002-06-01 12:26:43 +00:00
|
|
|
<xmlvalidate failonerror="no">
|
|
|
|
<fileset dir="${project.dir}" includes="**/*.xml"/>
|
|
|
|
<xmlcatalog refid="mycatalog"/>
|
2018-02-28 07:58:59 +01:00
|
|
|
</xmlvalidate></pre>
|
2002-09-09 02:50:35 +00:00
|
|
|
|
2018-02-28 07:58:59 +01:00
|
|
|
<p>Scan all XML files in the project, using a predefined catalog to map URIs to local files.</p>
|
2002-09-09 02:50:35 +00:00
|
|
|
<pre>
|
2002-06-01 12:26:43 +00:00
|
|
|
<xmlvalidate failonerror="no">
|
|
|
|
<fileset dir="${project.dir}" includes="**/*.xml"/>
|
|
|
|
<xmlcatalog>
|
2018-03-08 08:21:30 +01:00
|
|
|
<dtd publicId="-//ArielPartners//DTD XML Article V1.0//EN"
|
2002-06-01 12:26:43 +00:00
|
|
|
location="com/arielpartners/knowledgebase/dtd/article.dtd"/>
|
|
|
|
</xmlcatalog>
|
2018-02-28 07:58:59 +01:00
|
|
|
</xmlvalidate></pre>
|
|
|
|
<p>Scan all XML files in the project, using the catalog defined inline.</p>
|
2001-04-10 04:47:00 +00:00
|
|
|
|
2002-09-23 14:59:42 +00:00
|
|
|
<pre>
|
|
|
|
<xmlvalidate failonerror="yes" lenient="no" warn="yes">
|
|
|
|
<fileset dir="xml" includes="**/*.xml"/>
|
|
|
|
<attribute name="http://xml.org/sax/features/validation" value="true"/>
|
|
|
|
<attribute name="http://apache.org/xml/features/validation/schema" value="true"/>
|
2004-06-11 15:29:27 +00:00
|
|
|
<attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
2018-02-28 07:58:59 +01:00
|
|
|
</xmlvalidate></pre>
|
|
|
|
<p>Validate all <samp>.xml</samp> files in <samp>xml</samp> directory with the parser configured to
|
|
|
|
perform XSD validation. Note: The parser must support the
|
|
|
|
feature <var>http://apache.org/xml/features/validation/schema</var>. The <a href="schemavalidate.html">schemavalidate</a>
|
|
|
|
task is better for validating W3C XML Schemas, as it extends this task with the right options
|
|
|
|
automatically enabled, and makes it easy to add a list of schema files/URLs to act as sources.</p>
|
2004-06-11 15:29:27 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-03-10 20:17:33 +01:00
|
|
|
<!-- Convert path to URL format -->
|
2004-06-11 15:29:27 +00:00
|
|
|
<pathconvert dirsep="/" property="xsd.file">
|
|
|
|
<path>
|
|
|
|
<pathelement location="xml/doc.xsd"/>
|
|
|
|
</path>
|
|
|
|
</pathconvert>
|
|
|
|
|
2018-03-08 08:21:30 +01:00
|
|
|
<xmlvalidate file="xml/endpiece-noSchema.xml" lenient="false" failonerror="true" warn="true">
|
|
|
|
<attribute name="http://apache.org/xml/features/validation/schema" value="true"/>
|
2004-06-11 15:29:27 +00:00
|
|
|
<attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
2018-03-08 08:21:30 +01:00
|
|
|
<property name="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
|
|
|
|
value="${xsd.file}"/>
|
2018-02-28 07:58:59 +01:00
|
|
|
</xmlvalidate></pre>
|
|
|
|
<p>Validate the file <samp>xml/endpiece-noSchema.xml</samp> against the
|
|
|
|
schema <samp>xml/doc.xsd</samp>.</p>
|
2001-04-10 04:47:00 +00:00
|
|
|
</body>
|
|
|
|
</html>
|