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>
|
|
|
|
|
|
|
|
<h2><a name="xmlvalidate">XMLValidate</a></h2>
|
|
|
|
<h3>Description</h3>
|
2002-04-22 08:56:13 +00:00
|
|
|
|
2004-02-24 14:27:51 +00:00
|
|
|
<p>This task checks that XML files are valid (or only well formed). The
|
2002-04-22 08:56:13 +00:00
|
|
|
task uses the SAX2 parser implementation provided by JAXP by default
|
2002-09-09 16:49:23 +00:00
|
|
|
(probably the one that is used by Ant itself), but one can specify any
|
|
|
|
SAX1/2 parser if needed.</p>
|
2001-04-10 04:47:00 +00:00
|
|
|
|
2002-09-23 14:59:42 +00:00
|
|
|
<p>This task supports the use of nested
|
2004-02-24 14:27:51 +00:00
|
|
|
<li><a href="../CoreTypes/xmlcatalog.html"><tt><xmlcatalog></tt></a> elements</li>
|
|
|
|
<li><tt><dtd></tt> elements which are used to resolve DTDs and entities</li>
|
|
|
|
<li><tt><attribute></tt> elements which are used to set features on the parser.
|
|
|
|
These can be any number of
|
|
|
|
<a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"><tt>http://xml.org/sax/features/</tt></a>
|
|
|
|
or other features that your parser may support.</li>
|
2004-06-11 15:29:27 +00:00
|
|
|
<li><tt><property></tt> elements, containing string properties
|
2002-09-23 14:59:42 +00:00
|
|
|
</p>
|
2002-06-01 12:26:43 +00:00
|
|
|
|
2004-06-11 22:47:23 +00:00
|
|
|
<p><b>Warning</b> : JAXP creates by default a non namespace aware parser.
|
|
|
|
The <tt>"http://xml.org/sax/features/namespaces"</tt> feature is set
|
|
|
|
by default to <tt>false</tt> by the JAXP implementation used by ant. To validate
|
|
|
|
a document containing namespaces,
|
|
|
|
set the namespaces feature to <tt>true</tt> explicitly by nesting the following element:
|
|
|
|
<pre>
|
|
|
|
<attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
|
|
|
</pre>
|
|
|
|
If you are using for instance a <tt>xsi:noNamespaceSchemaLocation</tt> 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 <tt>classname</tt> attribute of xmlvalidate, this warning
|
|
|
|
may not apply.</p>
|
|
|
|
|
|
|
|
|
2001-04-10 04:47:00 +00:00
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">file</td>
|
|
|
|
<td valign="top">the file(s) you want to check. (optionally can use an embedded fileset)</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">lenient</td>
|
|
|
|
<td valign="top">
|
2004-02-24 14:27:51 +00:00
|
|
|
if true, only check the XML document is well formed
|
|
|
|
(ignored if the specified parser is a SAX1 parser)
|
2001-04-10 04:47:00 +00:00
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">classname</td>
|
2002-04-22 08:56:13 +00:00
|
|
|
<td valign="top">the parser to use.</td>
|
2001-04-10 04:47:00 +00:00
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">classpathref</td>
|
2004-02-24 14:27:51 +00:00
|
|
|
<td valign="top">where to find the parser class. Optionally can use an embedded <tt><classpath></tt> element.</td>
|
2001-04-10 04:47:00 +00:00
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">failonerror</td>
|
|
|
|
<td valign="top">fails on a error if set to true (defaults to true).</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">warn</td>
|
|
|
|
<td valign="top">log parser warn events.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
2002-01-19 21:19:42 +00:00
|
|
|
|
|
|
|
<h3><a name="nested">Nested Elements</a></h3>
|
|
|
|
<h4>dtd</h4>
|
2004-02-24 14:27:51 +00:00
|
|
|
<p>
|
|
|
|
<tt><dtd></tt> is used to specify different locations for DTD resolution.
|
|
|
|
</p>
|
2002-01-19 21:19:42 +00:00
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td width="12%" valign="top"><b>Attribute</b></td>
|
|
|
|
<td width="78%" valign="top"><b>Description</b></td>
|
|
|
|
<td width="10%" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2002-07-09 21:06:15 +00:00
|
|
|
<td valign="top">publicId</td>
|
2002-01-19 21:19:42 +00:00
|
|
|
<td valign="top">Public ID of the DTD to resolve</td>
|
|
|
|
<td align="center" valign="top">Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2002-07-09 21:06:15 +00:00
|
|
|
<td valign="top">location</td>
|
2002-01-19 21:19:42 +00:00
|
|
|
<td valign="top">Location of the DTD to use, which can be a file,
|
|
|
|
a resource, or a URL</td>
|
|
|
|
<td align="center" valign="top">Yes</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
2002-06-01 12:26:43 +00:00
|
|
|
<h4>xmlcatalog</h4>
|
2004-02-24 14:27:51 +00:00
|
|
|
<p>The <a href="../CoreTypes/xmlcatalog.html"><tt><xmlcatalog></tt></a>
|
|
|
|
element is used to perform entity resolution.</p>
|
2002-09-23 14:59:42 +00:00
|
|
|
<h4>attribute</h4>
|
2004-06-11 15:29:27 +00:00
|
|
|
<p>The <tt><attribute></tt> element is used to set parser features.<br>
|
|
|
|
Features usable with the xerces parser are defined here :
|
|
|
|
<a href="http://xml.apache.org/xerces-j/features.html">Setting features</a><br>
|
|
|
|
|
|
|
|
SAX features are defined here:
|
|
|
|
<a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description"><tt>http://xml.org/sax/features/</tt></a><br>
|
|
|
|
</p>
|
2002-09-23 14:59:42 +00:00
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td width="12%" valign="top"><b>Attribute</b></td>
|
|
|
|
<td width="78%" valign="top"><b>Description</b></td>
|
|
|
|
<td width="10%" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">name</td>
|
|
|
|
<td valign="top">The name of the feature</td>
|
|
|
|
<td align="center" valign="top">Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">value</td>
|
|
|
|
<td valign="top">The boolean value of the feature</td>
|
|
|
|
<td align="center" valign="top">Yes</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</p>
|
2002-01-19 21:19:42 +00:00
|
|
|
|
2004-06-11 15:29:27 +00:00
|
|
|
<h4>property</h4>
|
|
|
|
<p>The <tt><property></tt> element is used to set properties.
|
|
|
|
These properties are defined here for the xerces XML parser implementation :
|
|
|
|
<a href="http://xml.apache.org/xerces-j/properties.html">XML Parser properties</a>
|
|
|
|
Properties can be used to set the schema used to validate the XML file.
|
|
|
|
</p>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td width="12%" valign="top"><b>Attribute</b></td>
|
|
|
|
<td width="78%" valign="top"><b>Description</b></td>
|
|
|
|
<td width="10%" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">name</td>
|
|
|
|
<td valign="top">The name of the feature</td>
|
|
|
|
<td align="center" valign="top">Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">value</td>
|
|
|
|
<td valign="top">The string value of the property</td>
|
|
|
|
<td align="center" valign="top">Yes</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
|
|
|
2002-01-19 21:19:42 +00:00
|
|
|
|
2001-04-10 04:47:00 +00:00
|
|
|
<h3>Examples</h3>
|
2002-09-09 02:50:35 +00:00
|
|
|
<pre>
|
2001-04-10 04:47:00 +00:00
|
|
|
<xmlvalidate file="toto.xml"/>
|
2002-09-09 16:49:23 +00:00
|
|
|
</pre>
|
|
|
|
Validate toto.xml
|
|
|
|
<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"/>
|
2002-01-19 21:19:42 +00:00
|
|
|
</xmlvalidate>
|
2002-09-09 02:50:35 +00:00
|
|
|
</pre>
|
|
|
|
Validate all .xsl files in src/style, but only warn if there is an error, rather than
|
|
|
|
halt the build.
|
|
|
|
<pre>
|
2002-09-09 16:49:23 +00:00
|
|
|
|
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"/>
|
|
|
|
</xmlvalidate>
|
2002-09-09 02:50:35 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
Validate a struts configuration, using a local copy of the DTD.
|
2002-09-09 16:49:23 +00:00
|
|
|
<pre>
|
2002-06-01 12:26:43 +00:00
|
|
|
<xmlvalidate failonerror="no">
|
|
|
|
<fileset dir="${project.dir}" includes="**/*.xml"/>
|
|
|
|
<xmlcatalog refid="mycatalog"/>
|
|
|
|
</xmlvalidate>
|
2002-09-09 02:50:35 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
Scan all XML files in the project, using a predefined catalog to map URIs to local files.
|
|
|
|
<pre>
|
2002-06-01 12:26:43 +00:00
|
|
|
<xmlvalidate failonerror="no">
|
|
|
|
<fileset dir="${project.dir}" includes="**/*.xml"/>
|
|
|
|
<xmlcatalog>
|
2002-07-09 21:06:15 +00:00
|
|
|
<dtd
|
2002-06-01 12:26:43 +00:00
|
|
|
publicId="-//ArielPartners//DTD XML Article V1.0//EN"
|
|
|
|
location="com/arielpartners/knowledgebase/dtd/article.dtd"/>
|
|
|
|
</xmlcatalog>
|
|
|
|
</xmlvalidate>
|
2002-09-09 02:50:35 +00:00
|
|
|
</pre>
|
|
|
|
Scan all XML files in the project, using the catalog defined inline.
|
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"/>
|
2002-09-23 14:59:42 +00:00
|
|
|
</xmlvalidate>
|
|
|
|
</pre>
|
2006-01-11 14:53:25 +00:00
|
|
|
Validate all .xml files in xml directory with the parser configured to perform XSD validation.
|
|
|
|
Note: The parser must support the feature
|
|
|
|
<code>http://apache.org/xml/features/validation/schema</code>.
|
|
|
|
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.
|
2004-06-11 15:29:27 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
<!-- Converts path to URL format -->
|
|
|
|
<pathconvert dirsep="/" property="xsd.file">
|
|
|
|
<path>
|
|
|
|
<pathelement location="xml/doc.xsd"/>
|
|
|
|
</path>
|
|
|
|
</pathconvert>
|
|
|
|
|
|
|
|
<xmlvalidate file="xml/endpiece-noSchema.xml" lenient="false"
|
|
|
|
failonerror="true" warn="true">
|
|
|
|
<attribute name="http://apache.org/xml/features/validation/schema"
|
|
|
|
value="true"/>
|
|
|
|
<attribute name="http://xml.org/sax/features/namespaces" value="true"/>
|
|
|
|
<property
|
|
|
|
name="http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"
|
|
|
|
value="${xsd.file}"/>
|
|
|
|
</xmlvalidate>
|
|
|
|
</pre>
|
|
|
|
<br>
|
|
|
|
Validate the file xml/endpiece-noSchema.xml against the schema xml/doc.xsd.
|
2002-09-23 14:59:42 +00:00
|
|
|
<br>
|
|
|
|
<hr>
|
2006-01-12 05:28:07 +00:00
|
|
|
<p align="center">Copyright © 2001-2002,2004-2006 The Apache Software Foundation. All rights
|
2001-04-10 04:47:00 +00:00
|
|
|
Reserved.</p>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|