Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is use="optional" in xsd redundant?

Tags:

xml

schema

xsd

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?

like image 208
kostja Avatar asked May 05 '11 14:05

kostja


People also ask

What is optional element in XSD?

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.

What is use in XSD?

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.

What is the use of minOccurs and maxOccurs in XSD?

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.

What is the default minOccurs in XSD?

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.


1 Answers

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 is optional)

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".

like image 88
blubb Avatar answered Oct 08 '22 07:10

blubb