Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between <all> <sequence> <choice> and <group> in XSD?

What is the difference between <all> <sequence> <choice> and <group> in XML Schema?

like image 751
huangweiwei Avatar asked Mar 29 '16 13:03

huangweiwei


People also ask

What is the difference between the sequence and all elements?

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')

What does XSD choice mean?

<xsd:choice> ElementAllows one and only one of the elements contained in the selected group to be present within the containing element.

What is a sequence in XSD?

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.

What is the difference between element and attribute in XSD?

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


1 Answers

When to use xsd:all, xsd:sequence, xsd:choice, or xsd:group:

  • Use xsd:all when all child elements must be present, independent of order.
  • Use xsd:sequence when child elements must be present per their occurrence constraints and order does matters.
  • Use xsd:choice when one of the child element must be present.
  • Use 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.

like image 135
kjhughes Avatar answered Oct 15 '22 19:10

kjhughes