Verification schemes, how to display convenient messages for verification?

Is there a way to avoid or configure the scheme to display more convenient messages?

I am parsing a string and using reg ex to interpret them, but there may be a better way.

Ex.

"cvc-complex-type.2.4.b: The content of element 'node' is not complete. One of '{\"\":offer,\"\":links}' is expected." 

Instead, I want:

 "The element 'node' is not complete. The child elements 'offer' and 'links' are expected." 

Again, I solved the problem by creating an extra layer that checks it. But when I need to use an XML tool with schema validation, crypt messages are displayed on the screen.

thanks

+4
source share
3 answers

I asked a similar question a while ago.

My conclusion was that there is no way to correlate errors and that you need to do something yourself.

Hope someone out there can do better!

0
source

Not that I knew. You may have to create your own custom code to adapt error messages. One way could be to identify a set of regular expressions that can pull the appropriate snippets of validation error messages, and then include them again in your own error messages. Something like this comes to mind (not optimized, does not handle the general case, etc., but I think you will understand this idea):

 String uglyMessage = "cvc-complex-type.2.4.b: The content of element 'node' is not complete. One of '{\"\":offer,\"\":links}' is expected."; String findRegex = "cvc-complex-type\\.2\\.4\\.b: The content of element '(\\w+)' is not complete\\. One of '\\{\"\":(\\w+),\"\":(\\w+)}' is expected\\."; String replaceRegex = "The element '$1' is not complete. The child elements '$2' and '$3' are expected."; String userFriendlyMessage = Pattern.compile(findRegex).matcher(uglyMessage).replaceAll(replaceRegex); System.out.println(userFriendlyMessage); // OUTPUT: // The element 'node' is not complete. The child elements 'offer' and 'links' are expected. 

I suspect that these validator error messages are vendor-specific, so if you do not have control over the XML validation mechanism in the deployed application, this may not work for you.

+3
source

We use Schematron to display friendly error messages to the user if the XML that he sends to us is erroneous. Our current implementation is a little simplified, especially in the following points:

  • Error message text encoded in schema rules
  • For each new XML type (i.e., a new XSD schema), you must manually add schema rules

However, this can be easily eliminated by the following processing:

  • Schematron rules must contain unique error message codes, while the actual selection of message text (including I18n problems) must be made out of scope.
  • Basic rules can be generated from an XSD scheme using XSD for the Schematron converter (available at http://www.schematron.com/resources.html )
+1
source

All Articles