Hi Zoltan,

validate(myXMLDoc, "/home/mySchema.xsd") -- works
valiadte(mySchema, "/home/XMLSchema.xsd") -- fails

Does anyone know if this approach is valid or even if Xerces 2.0.1
Supports validating a schema directly in this way?

Yes, this is possible to do but unfortunately Xerces 2.0.1 has a few bugs with regards to using the SchemaForSchemas to validate a schema document. There are two problems:


1) Xerces doesn't allow the use of "xs:anySimpleType" in schemas which will cause Xerces to fail.
2) The SchemaForSchemas place facet restrictions on the anySimpleType which also fails.


So, this means that you will get errors in the SchemaForSchemas before Xerces even tries to validate your schema document.

private static String extSchemaProp
= "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";;


This is your problem. you can't use the external-noNamespaceSchemaLocation property because the schemas you're trying to validate use a targetNamespace so you have to use the following property:

"http://apache.org/xml/properties/schema/external-schemaLocation";

and to validate a W3C XML Schema it should be set to the following value:

"http://www.w3.org/2001/XMLSchema schemaURL"

Cheers,
/Eddie

private boolean validate(InputSource xmlSource, String schemaURL) {

valid = true;
try {
    SAXParser parser = new SAXParser();

    // configures the xerces parser for schema validation.
    parser.setFeature(validationFeat, true);
    parser.setFeature(schemaValidationFeat, true);

       //validate against the given schemaURL
    parser.setProperty(extSchemaProp, schemaURL);

    // binds custom error handler to parser
    ErrorHandler handler = new ValidatingHandler();
    parser.setErrorHandler (handler);

    // parse (validates) the xml
    parser.parse(xmlSource);

} catch (SAXNotRecognizedException snre) {
        System.out.println("SAX not recognised " + snre);
    valid = false;
} catch (SAXException se) {
               System.out.println("SAX parser " + se);
        valid = false;
} catch (Exception e) {
         System.out.println("error parsing " + e);
         valid = false;
}

  return valid;
}






_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to