Hello Guys,
a small confusion to check with.
I am validating xml file with its xsd file. If there's any error, SAXException will take care of it & displayed as stack trace. but Issue is, it shows valiation error for first occured single level, meaning, if there are couple of places, where xml file is wrong, validator will display only 1st occurance & then it'll exit.
Is there any possibility, whereby i can iterate complete xml file, & display all the possible validation errors within xml file?
For sample, am using the following code.
public
String validateSIXml(File selectedFile, File xsdFile) {
StringBuffer errorMsg = new StringBuffer();
Validator validator = null;
DOMSource source = null;
DOMResult result =null;
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
Source schemaFile = new StreamSource(xsdFile);
Schema schemaXSD = schemaFactory.newSchema( schemaFile );
validator = schemaXSD.newValidator();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse( selectedFile );
source = new DOMSource(document);
result = new DOMResult();
validator.validate( source,result );
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SAXException saxe) {
errorMsg.append(saxe.getMessage());
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}
Any guidence in this will be helpful.
[ September 04, 2007: Message edited by: Amit Jadhav ]