File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes multiple validation errors in xml for given xsd with java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "multiple validation errors in xml for given xsd with java" Watch "multiple validation errors in xml for given xsd with java" New topic

multiple validation errors in xml for given xsd with java

Amit Jadhav

Joined: Dec 11, 2002
Posts: 5
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();
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse( selectedFile );
source = new DOMSource(document);
result = new DOMResult();
validator.validate( source,result );
} catch (FileNotFoundException fnfe) {
} catch (IOException ioe) {
} catch (SAXException saxe) {
} catch (ParserConfigurationException pce) {
} catch(Exception e){
Any guidence in this will be helpful.
[ September 04, 2007: Message edited by: Amit Jadhav ]

Thnks & Rgrds<br />@mit
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
I dont think this is possible because the correct syntax for the remainder of the XML document can't be determined as long as the error is there.

IF (really big if) your program could automatically figure out the correct syntax and generate it you might be able to use a "pipeline" processing style to output a corrected document.

I agree. Here's the link:
subject: multiple validation errors in xml for given xsd with java
It's not a secret anymore!