Queries should be able to handle all possible combinations of values of input data. This includes handling any potential variations in the data, and considering the impact of missing or empty values.
It is important to consider variations in the input documents that may cause incorrect results or dynamic errors. Some common problems occur when:
For example, the expressions $prod[name eq "Floppy Sun Hat"]
and substring($prod/name, 1, 30)
raise an error if there is more than one name
child. The expression $prod/name != "Floppy Sun Hat"
evaluates to true
if two name
children exist and either one is not equal to Floppy Sun Hat
.
For example, the expression $prod/price - $prod/discount
returns the empty sequence if there is no discount
element.
For example, the expression max($prod/number)
raises a type error if the product number is N/A
instead of an integer.
Especially zero and negative numbers where a positive number was expected.
You should not assume that because an input document is validated by a schema it must be exactly as you expect. A schema can validate, for example, that a required element is present, but other assumptions might be made that cannot be validated by a schema. For example, the constraint "if the discounted
attribute is true
, a discount
child ...
No credit card required