This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown

multiple validation errors in xml for given xsd with java

Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic