Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 42606 invoked from network); 23 Feb 2005 12:51:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 23 Feb 2005 12:51:11 -0000 Received: (qmail 21515 invoked by uid 500); 23 Feb 2005 12:51:10 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 21393 invoked by uid 500); 23 Feb 2005 12:51:09 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 21380 invoked by uid 500); 23 Feb 2005 12:51:09 -0000 Received: (qmail 21372 invoked by uid 99); 23 Feb 2005 12:51:09 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 23 Feb 2005 04:51:08 -0800 Received: (qmail 42570 invoked by uid 1365); 23 Feb 2005 12:51:07 -0000 Date: 23 Feb 2005 12:51:07 -0000 Message-ID: <20050223125107.42569.qmail@minotaur.apache.org> From: stevel@apache.org To: ant-cvs@apache.org Subject: cvs commit: ant/docs/manual/OptionalTasks schemavalidate.html X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N stevel 2005/02/23 04:51:07 Modified: src/main/org/apache/tools/ant/taskdefs/optional SchemaValidate.java docs/manual/OptionalTasks schemavalidate.html Log: Worked out how to validate XSD files themselves. Changes to task made, and the examples of the task now show how to do this. Revision Changes Path 1.4 +12 -3 ant/src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java Index: SchemaValidate.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SchemaValidate.java 22 Feb 2005 17:45:40 -0000 1.3 +++ SchemaValidate.java 23 Feb 2005 12:51:07 -0000 1.4 @@ -56,6 +56,8 @@ /** full checking of a schema */ private boolean fullChecking=true; + private boolean disableDTD=false; + /** * default URL for nonamespace schemas */ @@ -179,6 +181,14 @@ } /** + * flag to disable DTD support. + * @param disableDTD + */ + public void setDisableDTD(boolean disableDTD) { + this.disableDTD = disableDTD; + } + + /** * init the parser : load the parser class, and set features if necessary It * is only after this that the reader is valid * @@ -186,7 +196,6 @@ */ protected void initValidator() { super.initValidator(); - XMLReader xmlReader = getXmlReader(); //validate the parser type if(isSax1Parser()) { throw new BuildException(ERROR_SAX_1); @@ -204,8 +213,8 @@ //enable schema checking setFeature(XmlConstants.FEATURE_XSD_FULL_VALIDATION,fullChecking); - //turn off DTDs - setFeatureIfSupported(XmlConstants.FEATURE_DISALLOW_DTD,true); + //turn off DTDs if desired + setFeatureIfSupported(XmlConstants.FEATURE_DISALLOW_DTD,disableDTD); //schema declarations go in next addSchemaLocations(); } 1.3 +62 -104 ant/docs/manual/OptionalTasks/schemavalidate.html Index: schemavalidate.html =================================================================== RCS file: /home/cvs/ant/docs/manual/OptionalTasks/schemavalidate.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- schemavalidate.html 22 Feb 2005 16:04:20 -0000 1.2 +++ schemavalidate.html 23 Feb 2005 12:51:07 -0000 1.3 @@ -15,8 +15,8 @@
  • The parser is created validating and namespace aware
  • Validation is turned on.
  • -
  • and Schema validation is turned on.
  • -
  • Any default schema supplied is used as the no-namespace schema +
  • Schema validation is turned on.
  • +
  • Any no-namespace schema URL or file supplied is used as the no-namespace schema
  • All nested schema declarations are turned into the list of namespace-url bindings for schema lookup. @@ -50,35 +50,34 @@ Required - file - the file(s) you want to check. (optionally can use an embedded fileset) - No + classname + the parser to use. + No - defaultSchemaFile - - filename of a no-namespace XSD file to provide the - schema for no-namespace XML content. - - No + classpathref + where to find the parser class. + Optionally can use an embedded <classpath> element. + No - noNamespaceURL + disableDTD - URL of a no-namespace XSD file to provide the - schema for no-namespace XML content. + Flag to disable DTD support. DTD support is needed to + validate XSD files themselves, amongst others. - No + No - default false - noNamespaceFile - - filename of a no-namespace XSD file to provide the - schema for no-namespace XML content. - + failonerror + fails on a error if set to true (defaults to true). + No + + + file + the file(s) you want to check. (optionally can use an embedded fileset) No - fullchecking @@ -86,6 +85,7 @@ No - default true + lenient @@ -94,20 +94,20 @@ No - classname - the parser to use. - No - - - classpathref - where to find the parser class. - Optionally can use an embedded <classpath> element. - No + noNamespaceFile + + filename of a no-namespace XSD file to provide the + schema for no-namespace XML content. + + No - failonerror - fails on a error if set to true (defaults to true). - No + noNamespaceURL + + URL of a no-namespace XSD file to provide the + schema for no-namespace XML content. + + No warn @@ -227,79 +227,37 @@

    Examples

      -<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. - + <schemavalidate + noNamespaceFile="document.xsd" + file="xml/endpiece.xml"> + </schemavalidate> + +Validate a document against an XML schema. The document does not declare +any schema itself, which is why the noNamespaceFile is needed. +
      +    <presetdef name="validate-soap">
      +      <schemavalidate >
      +        <schema namespace="http://schemas.xmlsoap.org/ws/2003/03/addressing"
      +          file="${soap.dir}/ws-addressing.xsd" />
      +        <schema namespace="http://www.w3.org/2003/05/soap-envelope"
      +          file="${soap.dir}/soap12.xsd" />
      +        <schema namespace="http://schemas.xmlsoap.org/wsdl/"
      +          file="${soap.dir}/wsdl.xsd" />
      +        <schema namespace="http://www.w3.org/2001/XMLSchema"
      +          file="${soap.dir}/XMLSchema.xsd" />
      +        </schemavalidate>
      +    </presetdef>
      +
    +Declare a new preset task, <validate-soap>, that validates +XSD and WSDL documents against the relevant specifications. +To validate XSD documents, you also need XMLSchema.dtd and datatypes.dtd in +the same directory as XMLSchema.xsd, or pointed to via the catalog. All +these files can be fetched from +the W3C.
      -<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"/>
      -  <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
      -</xmlvalidate>
      +    <validate-soap file="xml/test.xsd"/>
       
    -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/schema
    feature. - -
    -
      -
      -<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>
      -
    -
    -Validate the file xml/endpiece-noSchema.xml against the schema xml/doc.xsd. +Use the preset task defined above to validate an XML Schema document.

    Copyright © 2001-2002,2004-2005 The Apache Software Foundation. All rights --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org