java left logo
java middle logo
java right logo

Home arrow Other API Tips
Main Menu
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog

Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews

Registered Users: 4118
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
How to use XMLValidate task E-mail
User Rating: / 2



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

  • <xmlcatalog> elements
  • <dtd> elements which are used to resolve DTDs and entities
  • <attribute> elements which are used to set features on the parser. These can be any number of or other features that your parser may support.
  • <property> elements, containing string properties

    Warning : JAXP creates by default a non namespace aware parser. The "" feature is set by default to false by the JAXP implementation used by ant. To validate a document containing namespaces, set the namespaces feature to true explicitly by nesting the following element:

      <attribute name="" value="true"/>
    If you are using for instance a xsi:noNamespaceSchemaLocation attribute in your XML files, you will need this namespace support feature.

    If you are using a parser not generated by JAXP, by using the classname attribute of xmlvalidate, this warning may not apply.


    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

    Nested Elements


    <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 parser features.
    Features usable with the xerces parser are defined here : Setting features
    SAX features are defined here:

    Attribute Description Required
    name The name of the feature Yes
    value The boolean value of the feature Yes


    The <property> element is used to set properties. These properties are defined here for the xerces XML parser implementation : XML Parser properties Properties can be used to set the schema used to validate the XML file.

    Attribute Description Required
    name The name of the feature Yes
    value The string value of the property Yes


    <xmlvalidate file="toto.xml"/>
    Validate toto.xml
    <xmlvalidate failonerror="no" lenient="yes" warn="yes"
      <fileset dir="src" includes="style/*.xsl"/>
    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"
    Validate a struts configuration, using a local copy of the DTD.
    <xmlvalidate failonerror="no">
      <fileset dir="${project.dir}" includes="**/*.xml"/>
      <xmlcatalog refid="mycatalog"/>
    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"/>
             publicId="-//ArielPartners//DTD XML Article V1.0//EN"
    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="" value="true"/>
      <attribute name=""  
      <attribute name="" value="true"/>
    Validate all .xml files in xml directory with the parser configured to perform schema validation. Note: The parser must support the
    <pathconvert dirsep="/" property="xsd.file">
       <pathelement location="xml/doc.xsd"/>
    <xmlvalidate file="xml/endpiece-noSchema.xml" lenient="false"
      failonerror="true" warn="true">
      <attribute name=""
      <attribute name="" value="true"/>

    Validate the file xml/endpiece-noSchema.xml against the schema xml/doc.xsd.

    Source: Apache Ant

     Related Tips

    < Prev   Next >

    Page 1 of 0 ( 0 comments )

    You can share your information about this topic using the form below!

    Please do not post your questions with this form! Thanks.

    Name (required)

    E-Mail (required)

    Your email will not be displayed on the site - only to our administrator

    Comment Enable HTML code : Yes No

    java bottom left
    java bottom middle
    java bottom right
    RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

    Home - About Us - Privacy Policy
    Copyright 2005 - 2008
    Java is a trademark of Sun Microsystems, Inc.