Does it matter for any purpose (validation, binding ...) if I define the use
of an xs:attribute
as optional
or do not define it at all?
If it is redundant, why is it provided at all?
Using <xsd:choice> in an XSD The element in the root schema has to be optional. Add attribute minOccurs="0" on the element to make it optional.
An XSD defines the structure of an XML document. It specifies the elements and attributes that can appear in an XML document and the type of data these elements and attributes can contain. This information is used to verify that each element or attribute in an XML document adheres to its description.
The minOccurs attribute specifies the minimum number of times that the element can occur. It can have a value of 0 or any positive integer. The maxOccurs attribute specifies the maximum number of times that the element can occur.
The default value for both the minOccurs and the maxOccurs attributes is 1. Thus, when an element such as comment is declared without a maxOccurs attribute, the element may not occur more than once.
Yes, it's redundant.
This section of the XSD Primer explains the gory details of occurrence constraints, but here's the relevant part:
(the default value of
use
isoptional
)
As with all explicitly specified values that match their defaults: It's just a way to distinguish "don't care" from "i actually want that value".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With