Custom Error Messages When XSD Validation Fails

I am checking an xml file using xsd and I want to return meaningful messages to the user. is there any way to create custom posts in xsd.

+4
source share
2 answers

The answers β€œno” and β€œyes” (or β€œyes, but ...”) apply here, depending on what you want; unfortunately, for all practical purposes, the answer is no.

The XSD specification does not specify or restrict APIs or user interfaces, so there is no standard way to indicate in the XSD schema document which message to provide to the user if any restriction is violated. It is perfectly legitimate that circuit processors allow you to somehow manage error messages, and the xs: appinfo element is partially enabled to make such things doable. But I don’t know any schema validators that really provide such an object (I would be happy to know what this does).

One possible workaround: XSD offers specific error codes for use by validators, so if your validator provides an API for validation results, you can identify errors that have occurred and use error codes and location information to generate a suitable message error for your users. The same may be true if your processor produces written output that you can analyze.

The easiest way to get great custom error messages that are customizable based on what went wrong is to use Schematron, which determines that processors use the error messages specified by the schema author. (I expect there are some issues with internationalization, but I don't know any details.)

+4
source

Use Schematron , which uses a set of rules β€” each with a custom error message β€” to validate the document. All of these error messages are displayed in a validation report called SVRL, along with the corresponding error location (XPath) in the input document.

0
source

Source: https://habr.com/ru/post/1440870/


All Articles