[xsd-users] Handling of complex restrictions on types

Boris Kolpackov boris at codesynthesis.com
Mon Mar 23 08:14:29 EDT 2015


Hi Yury,

Yury Zaytsev <yury.zaytsev at traveltainment.de> writes:

> I've had a look at the generated code, and so far was unable to find 
> anything that handles them, so is it correct to assume that they are 
> simply ignored at the moment, or am I missing something obvious?

Yes, there is no runtime validation of schema constraints. Some
of them are translated to compile-time constraints (for example,
you won't be able to create a type with a required element without
supplying its value). But nothing at runtime.


> Ideally, I would like to have all of them checked at runtime, so that the 
> constructors and/or setters would raise an exception when the restrictions 
> are not adhered to.

While some could argue that this is not the right way to handle it (i.e.,
this is a "programming error", from the object model's point of view), I
can also see why some might want this behavior. The good question to ask
is what are you going to do when such an exception is thrown? In
particular, there is almost certainly no way to automatically recover
from it.


> Potentially, I can re-implement these restrictions manually in the code, 
> but on one hand, it's a large amount of work, and, on the other hand, it's 
> hardly maintainable, because as soon as the restrictions change in the 
> schema, my code immediately gets out of sync with it.

Yes, all valid points. Unfortunately, implementing restriction
validation in the generated code if probably an order of magnitude
larger amount of work. And at this stage we have to plans to
do it.

If you do decide to implement this yourself, you may want to check
the type customization mechanism. This way you will be able to add
the extra checks transparently wrt to the users of the object model.

Boris



More information about the xsd-users mailing list