Does anyone know how to validate whether a schema is a valid schema without 
creating an instance document and then validating that first?

I have code which uses a SAX parser and works when validating an xml 
instance document against its schema however Im trying to use this same code 
to pass in a schema and the Schema reference and validate one against the 
other. e.g.

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?

The code Im using is listed below. Im getting the following error when I run 
it...

"schema_reference.4: Failed to read schema document 'null', because 1) could 
not find the document; 2) the document could not be read; 3) the root 
element of the document is not <xsd:schema>."

...even though the document does exist on the file system, can be read by my 
application and does have the root element <xsd:schema> for both schemas.

Any help anyone can give would be much appreciated.
Cheers

-----------

private static String validationFeat 
=               "http://xml.org/sax/features/validation";;

private static String schemaValidationFeat 
=       "http://apache.org/xml/features/validation/schema";;

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

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]

Reply via email to