Reputation: 139
I've been using XML Schema 1.1 because I want to define some assertions in the schema. The thing is whether I can handle any assertion errors as simple warnings.
The reason is that any inconsistencies are automatically handled in my web site, so I would like to notify the user what changes have been made.
Maybe there is a suitable alternative to "assert" that I'm not aware of.
Upvotes: 2
Views: 548
Reputation: 25034
Whether an invalid document is the cause of an error or a warning is not a function of the schema; it is determined by the validator and the invoker of the validator.
Most validators by default assume that they should raise an error on invalid input, but there is nothing that requires that behavior. The validator you are using may have an invocation-time option that allows you to request a warning, instead -- or if you are invoking a parser from a language like Java, you can of course catch the exception yourself. You can almost certainly identify whether the cause of invalidity was a false assertion by examining the error code supplied by the validator.
And if you are a user of any validator (especially if you are a paying customer), you might consider letting the developers know that you would like an interface to the validator that behaves differently; it's obvious that they will never know if you don't tell them.
Upvotes: 0
Reputation: 111551
No, XSD has no such notion of warning, and does not directly support user-controlled messaging regarding constraint violations.
You might look into Schematron where assertion messages and @role
and @flag
attributes can be specified.
Update per OP comment:
Yes, you could write a custom SAX Error Handler to intercept and change a validating parser's default error messages. (See Tip: Validation and the SAX ErrorHandler interface) This wouldn't have natural representation declaratively in the XSD itself, however, unless you also leveraged xsd:appinfo
in some creative manner.
Upvotes: 1