Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple validation errors in xml for given xsd with java  RSS feed

Amit Jadhav
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
William Brogden
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!