Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between XSD choice and enumeration?

Tags:

xml

xsd

What is the difference between XSD choice and enumeration?

like image 866
Albert T. Wong Avatar asked Mar 18 '11 21:03

Albert T. Wong


People also ask

What is XSD enumeration?

Enumerations are a base simple type in the XSD specification containing a list of possible values. Single-valued enumerations are shown as restrictions of the base simple type xs:token , as illustrated below: ? < xs:simpleType name=”GraduationPlanTypeMapType”>

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. Copy. <choice id = ID maxOccurs= (nonNegativeInteger | unbounded) : 1 minOccurs= nonNegativeInteger : 1 {any attributes with non-schema Namespace}...> Content: (annotation?, (

How do you create a choice in XML schemas?

Using <xsd:choice> in an XSD It has to be defined in XML schema definition of a nested XML content. The element in the root schema has to be optional. Add attribute minOccurs="0" on the element to make it optional.

What is complexType in XSD?

Definition and UsageThe complexType element defines a complex type. A complex type element is an XML element that contains other elements and/or attributes.


2 Answers

They are completely unrelated.

Choice indicates that within the content model of an element, you can use one of several child elements: for example within a document you have a choice of chapter or appendix as child elements.

Enumeration is used to restrict the values that can appear in a text or attribute node, for example to say that the value of a color attribute must be red, green, or blue.

like image 166
Michael Kay Avatar answered Nov 15 '22 09:11

Michael Kay


XSD choice allows you to choose between zero or one elements/attributes. These can be of any type.

Enumeration are used in XSD simpleTypes to either restrict or extend one particular type to a set of values.

like image 23
Chris Sherlock Avatar answered Nov 15 '22 10:11

Chris Sherlock