on 08-17-2011 12:35 PM
Hello,
I have developed a Java mapping to validate an XML based on XSD.
I works fine and generates a message with error details.
I would like to create a report with all errors encountered during this Validation and to stop this message from being sent to the partner.
But this Java mapping stops at first error encountered and generates an error message with first error only even though document has more errors further.
Can anyone please let me know if there is an option to log all errors without allowing the message to go through?
Thanks.
Best Regards,
Shweta
if you are a good java programmer then you can catch al expcetions easily,refer this wiki
http://wiki.sdn.sap.com/wiki/display/XI/XIschemavalidationusingDOMparserviaJavacode
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, as abhishek mentioned when you validate the instance document (XML) using standard parsers then they validate based on the spec provided in XSD and they stop at the first error. The link given using dom parser via java code will also stop at the first error.
If you really want to validate the entire instance document then you might have to create a custom validator class which does validation for each and every fields and store it in an object like Vector or List or Map object. Then when you throw exception you can retrieve that Map object in the catch block and read all the individual error messages and display in log. This requires additional effort. In this case you dont rely on parser validation. Completely custom based.
Example:
Vector errorList = new Vector();
if the field name is SSN and if you see any alpha characters you add error for that field in the errorList
If(SSN.matches("[a-zA-Z]")){
do nothing
}else{
errorList.add("The fieldName SSN contains other than alpha characters");
}
Like that you have to add error string mesg in the errorList object and return the errorList at the end.
Hi Shweta Walaskar,
If you want to log all validation errors (do not want to stop on first validation error), you need to implement ErrorHandler. Check this [Link|http://www.ibm.com/developerworks/xml/library/x-javaxmlvalidapi/index.html#listing3].
Please note, it can catch only one fatal error.
Regards,
Raghu_Vamsee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But this Java mapping stops at first error encountered and generates an error message with first error only even though
document has more errors further.
In my opinion it is the default property of the parser to stop at the first error and will not go any further.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You need to write your java validation code in that way so that total validation takes place.
append the errror details into a string
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
For Example please see
http://wiki.sdn.sap.com/wiki/display/XI/XIschemavalidationusingDOMparserviaJavacode
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.