i am validating an xml according to schema present in it. i pass xml and schema to the
public boolean validation(
String pFileXmlOne, String... pSchemaNames)throws SAXException,IOException ,Exception
{
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Source[] lStreamSources = null;
Schema schema = null;
Validator validator = null;
Source source = new StreamSource(pFileXmlOne);
try {
lStreamSources = getStreamSource(pSchemaNames);
schema = factory.newSchema(lStreamSources);
validator = schema.newValidator();
validator.validate(source);
} catch (SAXException e) {
throw new SAXException(e.getMessage());
} catch (IOException e) {
throw new IOException(e.getMessage());
} catch (Exception e) {
throw new Exception(e.getMessage());
}
return true;
}
i am able to validate xml according to schema i pass.
but when i pass xml and schema not in xml.still it is validating instead of exception that schema could not be found.
can any one give inputs/ideas to get schema/dtd name of an xml dynamically.so that i can compare with schema name i pass and do validation accordingly if matches.