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 Ant itself), but one can specify any SAX1/2 parser if needed.
This task supports the use of nested
Attribute | Description | Required |
file | the file(s) you want to check. (optionally can use an embedded fileset) | No |
lenient | if true, only check the XML document is well formed (ignored if the specified parser is a SAX1 parser) | No |
classname | the parser to use. | No |
classpathref | where to find the parser class. Optionally can use an embedded <classpath> element. | No |
failonerror | fails on a error if set to true (defaults to true). | No |
warn | log parser warn events. | No |
<dtd> is used to specify different locations for DTD resolution.
Attribute | Description | Required |
publicId | Public ID of the DTD to resolve | Yes |
location | Location of the DTD to use, which can be a file, a resource, or a URL | Yes |
The <xmlcatalog> element is used to perform entity resolution.
The <attribute> element is used to set SAX Parser features. There can be any number of attributes set, as defined here: http://xml.org/sax/features/ A feature essentialy changes the mode of the parser.
Attribute | Description | Required |
name | The name of the feature | Yes |
value | The boolean value of the feature | Yes |
<xmlvalidate file="toto.xml"/>Validate toto.xml
<xmlvalidate failonerror="no" lenient="yes" warn="yes" classname="org.apache.xerces.parsers.SAXParser"> classpath="lib/xerces.jar"> <fileset dir="src" includes="style/*.xsl"/> </xmlvalidate>Validate all .xsl files in src/style, but only warn if there is an error, rather than halt the build.
<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>Validate a struts configuration, using a local copy of the DTD.
<xmlvalidate failonerror="no"> <fileset dir="${project.dir}" includes="**/*.xml"/> <xmlcatalog refid="mycatalog"/> </xmlvalidate>Scan all XML files in the project, using a predefined catalog to map URIs to local files.
<xmlvalidate failonerror="no"> <fileset dir="${project.dir}" includes="**/*.xml"/> <xmlcatalog> <dtd publicId="-//ArielPartners//DTD XML Article V1.0//EN" location="com/arielpartners/knowledgebase/dtd/article.dtd"/> </xmlcatalog> </xmlvalidate>Scan all XML files in the project, using the catalog defined inline.
<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"/> </xmlvalidate>Validate all .xml files in xml directory with the parser configured to perform schema validation. Note: The parser must support the
http://apache.org/xml/features/validation/schemafeature.
Copyright © 2001-2002,2004 The Apache Software Foundation. All rights Reserved.