aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
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
Author

multiple validation errors in xml for given xsd with java

Amit Jadhav
Greenhorn

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();
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 ]

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

Joined: Mar 22, 2000
Posts: 12803
    
    5
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.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multiple validation errors in xml for given xsd with java