What is the difference between <all> <sequence> <choice> and <group>
in XML Schema?
xsd:all - "child elements can appear in any order and each child element can occur zero or one time" (ie, maxOccurs can be 0 or 1) xsd:sequence - "child elements must appear in a sequence. Each child element can occur from 0 to any number of times" (ie, maxOccurs can be 0 or any number or 'unbounded')
<xsd:choice> ElementAllows one and only one of the elements contained in the selected group to be present within the containing element.
A sequence is the most common way of structuring elements in a schema. The following xsd defines foo as a sequence made of an arbitrary number of bar elements followed by a single baz element.
An attribute provides extra information within an element. Attributes are defined within an XSD as follows, having name and type properties. An Attribute can appear 0 or 1 times within a given element in the XML document. Attributes are either optional or mandatory (by default the are optional).
When to use xsd:all
, xsd:sequence
, xsd:choice
, or xsd:group
:
xsd:all
when all child elements must be present, independent of
order.xsd:sequence
when child elements must be present per their
occurrence constraints and order does matters.xsd:choice
when one of the child element must be present.xsd:group
as a way to wrap any of the above in order to name
and reuse in multiple locations within an XSD.Note that occurrence constraints can appear on xsd:all
, xsd:sequence
, or xsd:choice
in addition to the child elements to achieve various cardinality effects.
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