hi all,
i developed xml business component,where iam doing valdation based on schema.it is working fine when i pass xml and the schema used in xml.
if xml doc doesnt follow schema i am throwing exception
or else returning true.
but my problem is when i pass xml and other schema that is not defined in xml.At that time it is still validating
and throwing exception.
instead of getting exception schema not found.
please any one give inptust to resolve this issue.
here is my code
please help me to resolve this issue
i developed xml business component,where iam doing valdation based on schema.it is working fine when i pass xml and the schema used in xml.
if xml doc doesnt follow schema i am throwing exception
or else returning true.
but my problem is when i pass xml and other schema that is not defined in xml.At that time it is still validating
and throwing exception.
instead of getting exception schema not found.
please any one give inptust to resolve this issue.
here is my code
Code:
public boolean performValidation(String pFileXmlOne, String... pSchemaNames)
throws CAFException {
SchemaFactory factory = SchemaFactory
.newInstance("http://www.w3.org/2001/XMLSchema");
Source[] lStreamSources = null;
Schema schema = null;
Validator lValidator = null;
Source lSource = new StreamSource(pFileXmlOne);
// split schema string by delimiter
lStreamSources = getStreamSource(pSchemaNames);
logger.log(Level.INFO, myClassName + "total no of schemas"
+ lStreamSources.length);
try {
schema = factory.newSchema(lStreamSources);
} catch (SAXException e) {
// TODO Auto-generated catch block
logger.log(Level.INFO, myClassName
+ "sax exception in creating schema" + e.getMessage());
throw new SAXException(e.getMessage());
}
logger.log(Level.INFO, myClassName
+ " before creating validator object");
lValidator = schema.newValidator();
logger
.log(Level.INFO, myClassName
+ " after creating validator object");
try {
logger.log(Level.INFO, myClassName
+ " before performing validation");
lValidator.validate(lSource);
lValidator.setErrorHandler(new SimpleErrorHandler());
logger
.log(Level.INFO, myClassName
+ " after performing validation");
}
catch (SAXException e) {
// TODO Auto-generated catch block
logger.log(Level.INFO, myClassName + " sax exception"
+ e.getMessage());
throw new SAXException(e.getMessage());
} catch (IOException e) {
logger.log(Level.INFO, myClassName + " IOException"
+ e.getMessage());
throw new CAFException(e.getMessage());
}
catch(Exception e)
{
throw new SAXException("xml do not contain xsd,dtd|| xml is not following dtd or xsd");
}
return true;
}
Comment