Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom error messages when XSD validation fails

Tags:

xml

xsd

I am validating xml file with xsd and i want to return meaningful messages to user. is there any way to build custom messages in xsd.

like image 998
user307524 Avatar asked Oct 19 '12 19:10

user307524


People also ask

What is XSD validation error?

The schema is defined by the XSD. Schema errors occur where there is a problem with the structure or order of the file, or an invalid character is included. Schema errors prevent the validation being run in full because the file cannot be read. This means that errors cannot be traced to a particular record.

How do I know if a XSD file is valid?

All you have to do is just paste the XML and click on “Check XSD validity” button. In XML Schema Definition (XSD), we can verify: Checking the schema in its value. The same name field by checking its data type.

What is an XML validation error?

Typically, the system returns this error if there was a problem with authentication due to an error in the submitted Merchant Id, user, and/or password. The problem may also be due to the use of single quotes around the attribute (merchantId) value. Error validating xml data against the schema on line 1.

What does schema validation failed mean?

A schema validation error is an error in the required formatting of the electronic file established by the taxing authority which can be caused by missing or invalid information.


1 Answers

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

The XSD spec does not specify or constrain APIs or user interfaces, so there is no standard way to specify, in an XSD schema document, what message to give the user if a particular constraint is violated. It is perfectly legitimate for schema processors to allow you some way to control the error messages, and the xs:appinfo element is included in part to make things like that feasible. But I don't know of any schema validators that actually do provide that kind of facility (I'd be glad to learn of any that do).

One possible workaround: XSD does suggest specific error codes for use by validators, so if your validator provides an API for validation results, you may be able to identify the errors raised and use the error codes and location information to generate suitable error messages for your users. The same may be true if your processor produces written output you can parse.

The simplest way to get nifty user-specifiable error messages, customizable based on just what has gone wrong, is to use Schematron, which does prescribe that processors use error messages specified by the schema author. (I expect there is some handwaving somewhere to deal with internationalization, but I don't know any details.)

like image 55
C. M. Sperberg-McQueen Avatar answered Oct 06 '22 18:10

C. M. Sperberg-McQueen