Skip to Content
0
Former Member
Jul 06, 2009 at 07:16 AM

Catch all error information while validating xml content with xsd schema

453 Views

Hi experts,

I created a java mapping to validating the input xml content with xsd schema (schema validation). What I want is to catch all error message to the xml not just the first error. I used SAXParser in sapxmltoolkit.jar to do the schema validation. The below is a part of my java mapping.

XMLReader parser = XMLReaderFactory.createXMLReader("com.sap.engine.lib.xml.parser.SAXParser");

parser.setFeature( "http://xml.org/sax/features/validation" , true);

parser.setFeature( "http://apache.org/xml/features/validation/schema" , true);

parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",this.getClass().getClassLoader().getResourceAsStream(schema)); // schema is my schema name

parser.setErrorHandler(new ParseErrorHandler()); // ParseErrorHandler is my own ErrorHandler which extends DefaultHandler

parser.parse(new InputSource(new ByteArrayInputStream(sinput.getBytes())));

// In error handler, I comment all code so as not to throw any exception

public class ParseErrorHandler extends DefaultHandler

{

public void error(SAXParseException e) throws SAXException

{

// sSystem.out.println("Error" + e.getMessage());

// throw e;

}

public void fatalError(SAXParseException e)

{

// throw e;

// System.out.println("SAP Fatal Error" + e.getMessage());

}

}

Unfortunately the program always stopped while catching the first error. Check the below log.

com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException:

ERRORS :

cvc-simple-type : information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is not valid, because it's value does not satisfy the constraints of facet 'minLength' with value '1'.

cvc-data : information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is is not valid with respoct to the corresponding simple type definition.

cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is associated with invalid data.

cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]' is not valid with respect to it's complex type definition..

cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]' is not valid with respect to it's complex type definition..

cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]' is not valid with respect to it's complex type definition..

cvc-element : element information item '/:ShipNotice[1]/:Header[1]' is not valid with respect to it's complex type definition..

cvc-element : element information item '/:ShipNotice[1]' is not valid with respect to it's complex type definition..

-> com.sap.engine.lib.xml.parser.ParserException:

I tried using Xerces and JAXP to do validation, the same error happened. I have no idea on this. Does xi has its own error handler logic? Is there any body can make me get out of this?

Thanks.