File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XML Error Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Error Handling" Watch "XML Error Handling" New topic

XML Error Handling

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
I am parsing the XML using commons digester, xsd and a digester rules.

I want to identify sepcific error conditions in the input xml -

For e.g. - error case 1 - the length of the data in a particular tag is greater than the one in the xsd xs:pattern pattern for that tag
error case 2 - the data in a particular tag contains characters that are invalid as per the xs:pattern pattern for that tag

The parse method throws exception for these error. The saxException.getMessage() method returns the same message (of the format <error code>:<description>)for both of the above cases -

cvc-pattern-valid: Value '<tag_data_appears_here>' is not facet-valid with respect to pattern '<xsd_pattern_for_that_tag_appears_here'.

As a result I am not able to identify what went wrong - was it a length problem or a invalid character problem.

Is there any way I can do it? Also, is there any way I can configure digester to throw different error codes (cvc-patter-valid etc) for different error conditions like - incorrect tag hierarchy, incorrect tag names, a tag present more than the number of times it is allowed to be present etc? Currently, I see that the same error code appears in the sax exception for all of the error conditions.

Please help.


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
I agree. Here's the link:
subject: XML Error Handling
It's not a secret anymore!