all validation error from saxParser.parse

I am getting just the 1st error but I want all the errors in the 1st pass itself.

Attaching the code for reference also.

憌ould really appreciate you suggestion.

==code

public class EDITExtractSchema {

static Document document;

public void validateXMLVOusingXSD(String str)

{

try {

//create a SchemaFactory capable of understanding W3C XML Schemas (WXS)

SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

//Set the error handler to receive any error during Schema Compilation

XMLErrorHandler errorHandler = new XMLErrorHandler();

factory.setErrorHandler(errorHandler);

//set the resource resolver to customize resource resolution

//factory.setResourceResolver( new MyLSResourceResolver());

// load a WXS schema, represented by a Schema instance

File schemaFile = new File("C:/Temp/project2-CorrVO/XSDs/TaxExtract5498DetailVO.xsd");

Schema schema = factory.newSchema(new StreamSource(schemaFile));

SAXParserFactory spf = SAXParserFactory.newInstance();

//spf.setNamespaceAware(true);

//spf.setValidating(true);

spf.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

//Just set the Schema instance on SAXParserFactory

spf.setSchema(schema);

//Obtain the SAXParser instance

SAXParser saxParser = spf.newSAXParser();

//parser will parse the XML document but validate it using Schema instance

//saxParser.parse(new File(str), myHandler);

saxParser.parse(new File(str),new MyDefaulyHandler());

}catch(ParserConfigurationException e) {

System.out.println("ParserConfigurationException-" + e);

}catch (SAXException e) {

System.out.println("SAXException-" + e);

}

catch (Exception e) {

System.out.println("Exception-" + e);

}

/*// output the errors XML

XMLWriter writer = null;

try {

writer = new XMLWriter(OutputFormat.createPrettyPrint());

} catch (UnsupportedEncodingException e) {

System.out.println("validate error" + e);

e.printStackTrace();

}

try {

writer.write(errorHandler.geterrors());

} catch (IOException e) {

System.out.println("validate error" + e);

e.printStackTrace();

}

*/

}

//implement error handler

public static class XMLErrorHandler implements ErrorHandler {

private boolean valid = true;

public void reset() {

// Assume document is valid until proven otherwise

valid = true;

}

public boolean isValid() {

return valid;

}

public void warning(SAXParseException exception) throws SAXException{

System.out.println("Warning: " + exception.getMessage());

System.out.println(" at line " + exception.getLineNumber()

+ ", column " + exception.getColumnNumber());

System.out.println(" in entity " + exception.getSystemId());

valid = true;

}

public void error(SAXParseException exception) throws SAXException{

System.out.println("Error: " + exception.getMessage());

System.out.println(" at line " + exception.getLineNumber()

+ ", column " + exception.getColumnNumber());

System.out.println(" in entity " + exception.getSystemId());

valid = true;

/* // output the errors XML

XMLWriter writer = null;

try {

writer = new XMLWriter(OutputFormat.createPrettyPrint());

} catch (UnsupportedEncodingException e) {

System.out.println("validate error" + e);

e.printStackTrace();

}

try {

writer.write((Object)exception);

} catch (IOException e) {

System.out.println("validate error" + e);

e.printStackTrace();

}

*/

}

public void fatalError(SAXParseException exception) throws SAXException {

System.out.println("Fatal Error: " + exception.getMessage());

System.out.println(" at line " + exception.getLineNumber()

+ ", column " + exception.getColumnNumber());

System.out.println(" in entity " + exception.getSystemId());

valid = true;

}

}

public static class MyDefaulyHandler extends DefaultHandler {

private boolean valid = true;

public void reset() {

// Assume document is valid until proven otherwise

valid = true;

}

public boolean isValid() {

return valid;

}

public void warning(SAXParseException exception) throws SAXException{

System.out.println("Warning: " + exception.getMessage());

System.out.println(" at line " + exception.getLineNumber()

+ ", column " + exception.getColumnNumber());

System.out.println(" in entity " + exception.getSystemId());

valid = true;

}

public void error(SAXParseException exception) throws SAXException{

System.out.println("Error: " + exception.getMessage());

System.out.println(" at line " + exception.getLineNumber()

+ ", column " + exception.getColumnNumber());

System.out.println(" in entity " + exception.getSystemId());

valid = true;

/* // output the errors XML

XMLWriter writer = null;

try {

writer = new XMLWriter(OutputFormat.createPrettyPrint());

} catch (UnsupportedEncodingException e) {

System.out.println("validate error" + e);

e.printStackTrace();

}

try {

writer.write((Object)exception);

} catch (IOException e) {

System.out.println("validate error" + e);

e.printStackTrace();

}

*/

}

public void fatalError(SAXParseException exception) throws SAXException {

System.out.println("Fatal Error: " + exception.getMessage());

System.out.println(" at line " + exception.getLineNumber()

+ ", column " + exception.getColumnNumber());

System.out.println(" in entity " + exception.getSystemId());

valid = true;

}

}

public static void main(String[] args) {

EDITExtractSchema schemaClass = new EDITExtractSchema();

try {

schemaClass.validateXMLVOusingXSD("C:/Temp/project2-CorrVO/XSDs/TaxExtract5498DetailVO.xml");

}catch (Exception e) {

System.out.println("xml file read error Exception-" + e);

}

// */

}

}

--====

Regards,

Tapas

[6460 byte] By [RabiMa] at [2007-11-27 6:03:56]
# 1
You should repost the code and make sure you use the "code" button. Its too hard to read right now, and its not indented.
jellystonesa at 2007-7-12 16:47:22 > top of Java-index,Java Essentials,New To Java...
# 2
Hi,I could not attach code separately because it gives error on page when I hit the code button.thanks,RabiM
RabiMa at 2007-7-12 16:47:22 > top of Java-index,Java Essentials,New To Java...
# 3
> I am getting just the 1st error but I want all the> errors in the 1st pass itself.Once an XML parser finds an error, it reports it and stops trying to process the document. There's nothing you can do about that.
DrClapa at 2007-7-12 16:47:22 > top of Java-index,Java Essentials,New To Java...
# 4

No really, it will report all the error if you turn on the validation and implement the error hander methods(error()).

ALSO,

My XSD had "<xs:sequence>" which was causing the problem.

We had to change it to "<xs:all>". Now all the errors are getting reported.

thx!

RabiMa at 2007-7-12 16:47:22 > top of Java-index,Java Essentials,New To Java...