ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michael.gir...@objectweb.org
Subject Re: XMLValidate with schema
Date Thu, 27 May 2004 18:36:30 GMT
I have successfully validated an xml document using catalogs.  I'm using 
Xerces-J version 2.6.2.  This task supports OASIS catalogs allowing 
redirection of schema to local file system.


1. download and install xerces-j 2.6.2 (not sure if this works with older 
versions or not)
2. define your xmlvalidate task as shown below.
3. make sure that xercesImpl.jar and resolver.jar (both from the xerces 
2.6.2 distribution) are on the classpath.

The next steps are optional, and only required if you want to use catalog 
to redirect schema references to 
local file system or other location.
4. define CatalogManager.properties file and make sure the containing 
directory is on the classpath.
   see http://xml.apache.org/commons/components/resolver/tips.html for description of CatalogManager.properties
file used by the parser.
5. define an oasis catalog
   see http://www.oasis-open.org/committees/entity/spec.html for description of oasis catalog

TIP: if validation takes a long time, your xml probably references 
(directly or indirectly) schema residing on some other host.  If this is 
the case, you can improve the speed of the validation by making local 
copies of the schema and pointing to them using the catalog.  You can find 
out which schema are being retrieved from remote systems using the "verbosity=3" property
in CatalogManager.properties.

It took me 3 days to dig this all up, and make the xmlvalidate task work. 
I sure hope someone can benefit from this.

Maybe the owner of the xmlvalidate task could include some of this in the 
documentation for the task.

Michael Giroux

    <xmlvalidate failonerror="yes"
                 lenient="no"
                 warn="yes"
                 file="${dist.dir}/jonas-${j2ee.dd}"
                 classname="org.apache.xerces.parsers.SAXParser"
          >
      <attribute name="http://xml.org/sax/features/validation"
                 value="true"/>
      <attribute name="http://apache.org/xml/features/validation/schema"
                 value="true"/>
    </xmlvalidate>

Here is a copy of the CatalogManager.properties file I'm using:
# see: http://xml.apache.org/commons/components/resolver/tips.html
verbosity=3
prefer=system
catalogs=xmlcatalog.xml

Here is my xmlcatalog.xml file:
<?xml version="1.0"?>
<!--
  See: http://www.oasis-open.org/committees/entity/spec.html
  -->
<catalog 
  xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
  prefer="system">
  <!-- resolve specific systemId to a specific local file -->
  <system systemId="http://www.objectweb.org/jonas/ns/jonas-ejb-jar_4_1.xsd"
    uri="file:///C:/GIROUX/JOnAS/TCK_DD_Porting_Tool/JOnAS_XSD_Modified/jonas-ejb-jar_4_0.xsd"
    />
 
  <!-- change system prefix for objectweb schema to local file system --> 
  <rewriteSystem systemIdStartString="http://www.objectweb.org/jonas/ns" 
    rewritePrefix="file:///C:/GIROUX/JOnAS/TCK_DD_Porting_Tool/JOnAS_XSD_Modified" 
    />
 
  <!-- change system prefix for SUN schema to local file system -->
  <rewriteSystem systemIdStartString="http://java.sun.com/xml/ns/j2ee" 
    rewritePrefix="file:///C:/GIROUX/JOnAS/TCK_DD_Porting_Tool/SUN_XSD" 
    />
 
  <!-- change system prefix for IBM schema to local file system -->
  <rewriteSystem systemIdStartString="http://www.ibm.com/webservices/xsd" 
    rewritePrefix="file:///C:/GIROUX/JOnAS/TCK_DD_Porting_Tool/IBM_XSD" 
    />
</catalog>





michael.giroux@objectweb.org
05/27/2004 09:30 AM
Please respond to "Ant Users List"

 
        To:     "Ant Users List" <user@ant.apache.org>
        cc: 
        Subject:        Re: XMLValidate with schema


Jeremy,
Thanks a ton.  The classname="org.apache....." was the bit I was missing. 
I have confirmed that validation is not taking place using the schema.  I 
have tested using well-formed, but invalid XML, and did receive expected 
error messages.

I did notice that the validation takes quite a while on a rather simple 
XML, but I think this is caused by all the network access to the remote 
schemas.  I'll be very happy if you manage to get xmlcatalog to work.

Thanks.

Michael






Jeremy Aston <jeremyaston@yahoo.co.uk>
05/27/2004 08:42 AM
Please respond to "Ant Users List"

 
        To:     Ant Users List <user@ant.apache.org>
        cc: 
        Subject:        Re: XMLValidate with schema


This is a very basic example that does work.  I will
work on it to try and get a catalog to work as well.

One thing to note is that Xerces had (and I believe
still contains) a 'feature' that means it can only
validate against the first XSD if more than one
namespace is specfied.  That shafts the whole thing
anyways!  I've tried using jing for multiple xsd
validation but cannot get that to work.

Anyways...

build.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="validate-test" default="validate">
 
                 <target name="validate" description="Validate doc
files">
                                 <echo>${java.class.path}</echo>
                                 <xmlvalidate
                                                 failonerror="no"
                                                 lenient="no"
                                                 warn="yes"
                                                 file="test.xml"
 classname="org.apache.xerces.parsers.SAXParser"
 classpath="/java/xalan-j_2_6_0/bin/xercesImpl.jar">
                                                 <attribute
name="http://apache.org/xml/features/validation/schema"
 value="true"/>
                                 </xmlvalidate> 
                 </target>

</project>

test.xml

<?xml version="1.0" encoding="UTF-8"?>
<test xsi:noNamespaceSchemaLocation="schema/test.xsd"
xmlns="" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                 <aaa/>
</test>


schema/test.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="" elementFormDefault="qualified">
                 <xs:element name="test">
                                 <xs:complexType mixed="false">
                                                 <xs:choice>
                                                 <xs:element name="aaa" 
type="xs:string"/>
                                                 </xs:choice>
                                 </xs:complexType>
                 </xs:element>
</xs:schema>

You will need to change the path the to Xerces and the
xsd is in a sub folder.

Hope that helps start the process of sorting this once
and for all!

Rgds

Jeremy


 --- michael.giroux@objectweb.org wrote: > I have the
same problem, and have the additional
> requirement that I need 
> support for xmlcatalog to allow schema files to be
> located locally.
> 
> 
> Michael Giroux
> 
> 
> 
> 
> "WISE, Jon" <jwise@glos.ac.uk>
> 05/27/2004 05:30 AM
> Please respond to "Ant Users List"
> 
> 
>         To:     <user@ant.apache.org>
>         cc: 
>         Subject:        XMLValidate with schema
> 
> 
> I am finding it difficult to get XMLValidate to
> validate XML against a 
> schema. 
> 
> With many alternative attempts I get either
> 'successful validation' when 
> it there is an error in the xml, or 'element not
> defined' or 'parser 
> doesn't recognize feature
>
http://apache.org/xml/properties/schema/external-schemaLocation'
> 
> Does anyone have a set of files (i.e. build.xml,
> aaa.xml and aaa.xsd) for 
> a simple example to help me on the way? 
> 
> Jon Wise
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 
> 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 


 
 
 
____________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" 
your friends today! Download Messenger Now 
http://uk.messenger.yahoo.com/download/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message