cancel
Showing results for 
Search instead for 
Did you mean: 

Catch all error information while validating xml content with xsd schema

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

<h6>Hi experts,

<h6>

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

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

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

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

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

<h6>parser.setErrorHandler(new ParseErrorHandler()); // ParseErrorHandler is my own ErrorHandler which extends Default Handler

<h6>parser.parse(new InputSource(new ByteArrayInputStream(sinput.getBytes())));

<h6>

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

<h6>public class ParseErrorHandler extends DefaultHandler

<h6>{

<h6> public void error(SAXParseException e) throws SAXException

<h6> {

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

<h6> // throw e;

<h6> }

<h6>

<h6> public void fatalError(SAXParseException e)

<h6> {

<h6> // throw e;

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

<h6>

<h6> }

<h6>

<h6>}

<h6>

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

<h6>

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

<h6>ERRORS :

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

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

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

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

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

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

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

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

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

<h6>

<h6>

<h6>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 <h6>handler logic? Is there any body can make me get out of this?

<h6>Thanks.

prateek
Active Contributor
0 Kudos

Even the XML validation facility in PI 7.1 has the same limitation that it displays only the first error.

If you could succeed in your code, may be you can help SAP with it for improvement in XML validations.

Regards,

Prateek