Thank you very much for your response..
You are telling me to use JAXP for the validation. thats fine.
Post by panneerAlso I want to know whether I can use the classes in the
com.saxonica.validate package.
When you run the above code, you are using these classes implicitly, but via
a standard interface defined in JAXP. You can use the implementation classes
directly if you want, but you don't need to unless you need greater control.
validation.
I see many classes inside com.saxonica.validate package.
like AllElementValidator, AnyTypeValidator, AttributeValidator and....
ValidationStack, XSIAttributeHandler.
If this way is not possible then I can tell my leader the proper reason..
Please advice me in this..
Post by panneerPost by panneerI will explain what I want to achieve..
I have many XML documents and One schema document.
I want to validate all the xml documents against the schema document.
You can do this entirely using JAXP interfaces. Take a look at
SchemaValidatorHandlerExample.java in the samples directory (sample
applications are in the saxon-resources download package, available both on
the SourceForge site and on the www.saxonica.com download page). The essence
SchemaFactory schemaFactory;
// Set a system property to force selection of the Saxon
SchemaFactory implementation
// This is commented out because it shouldn't be necessary if
Saxon-SA is on the classpath;
// but in the event of configuration problems, try reinstating
it.
//
System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/200
1/XMLSchema",
// "com.saxonica.schema.SchemaFactoryImpl");
schemaFactory =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
System.err.println("Loaded schema validation provider " +
schemaFactory.getClass().getName());
schemaFactory.setErrorHandler(new LocalErrorHandler());
//create a grammar object.
Schema schemaGrammar;
if (args[0].equals("--")) {
// in this case, the schema must be identified using
xsi:schemaLocation
schemaGrammar = schemaFactory.newSchema();
} else {
schemaGrammar = schemaFactory.newSchema(new
File(args[0]));
"+args[0]);
}
Resolver resolver = new Resolver();
//create a validator to validate against the schema.
ValidatorHandler schemaValidator =
schemaGrammar.newValidatorHandler();
schemaValidator.setResourceResolver(resolver);
schemaValidator.setErrorHandler(new LocalErrorHandler());
schemaValidator.setContentHandler(new
LocalContentHandler(schemaValidator.getTypeInfoProvider()));
System.err.println("Validating "+args[1] +" against grammar
"+args[0]);
SAXParserFactory parserFactory =
SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setContentHandler(schemaValidator);
reader.parse(new InputSource(new
File(args[1]).toURI().toString()));
System.err.println("Validation successful");
} catch (SAXException saxe) {
exit(1, "Error: " + saxe.getMessage());
} catch (Exception e) {
e.printStackTrace();
exit(2, "Fatal Error: " + e);
}
}
The general structure is that it first loads the schema, then validates the
instance document. To validate multiple instance documents, just put the
validation code in a loop. The simplest change would be to create a new
ValidationHandler and SAXParser/XMLReader for each input document, though
you can probably reuse these objects if you need to.
Post by panneerAlso I want to know whether I can use the classes in the
com.saxonica.validate package.
When you run the above code, you are using these classes implicitly, but via
a standard interface defined in JAXP. You can use the implementation classes
directly if you want, but you don't need to unless you need greater control.
Post by panneerI just want to know is there any way that I can validate the
xml documents other than using command line utility.
Yes, see above.
Michael Kay
http://www.saxonica.com
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
saxon-help mailing list
https://lists.sourceforge.net/lists/listinfo/saxon-help