Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML Schema Indicators

XSD Indicators


With indicators, we can control how elements are used in a document.


Indicators

There are seven indicators:

Order indicators:

Occurrence indicators:

Group indicators:


Order Indicators

Order indicators are used to define the order of elements.

The All Indicator

The all indicator specifies that child elements can appear in any order, and each child element must appear only once:

  xs:complexType

    xs:all

     

     

   

 

Note: When using indicator, you can set to 0 or 1, while you can only set the indicator to 1 (which will be explained later and )。

The Choice Indicator

The choice indicator specifies that either one child element or another can appear (either/or):

  xs:complexType

    xs:choice

     

     

   

 

The Sequence Indicator

specifies that child elements must appear in a specific order:

   xs:complexType

    xs:sequence

     

     

   

 


Occurrence Indicators

Occurrence indicators are used to define how often an element can occur.

**Note:** For all "Order" and "Group" indicators (any, all, choice, sequence, group name, and group reference), the default value of maxOccurs and minOccurs is 1.

The maxOccurs Indicator

The maxOccurs indicator specifies the maximum number of times an element can occur:

  xs:complexType

    xs:sequence

     

     

   

 

The example above shows that the child element "child_name" can occur a minimum of one time (where the default value of minOccurs is 1) and a maximum of 10 times in the "person" element.

The minOccurs Indicator

The minOccurs indicator specifies the minimum number of times an element can occur:

  xs:complexType

    xs:sequence

     

     

      maxOccurs="10" minOccurs="0"/>

   

 

The example above shows that the child element "child_name" can occur a minimum of 0 times and a maximum of 10 times in the "person" element.

**Tip:** To allow an element to occur an unlimited number of times, use the declaration maxOccurs="unbounded":

A real example:

An XML file named "Myfamily.xml":

xsi:noNamespaceSchemaLocation="family.xsd">

  Hege Refsnes

  Cecilie

  Tove Refsnes

  Hege

  Stale

  Jim

  Borge

  Stale Refsnes

The XML file above has a root element named "persons". Inside this root element, we have defined three "person" elements. Each "person" element must contain one "full_name" element, and it can contain up to 5 "child_name" elements.

This is the schema file "family.xsd":

elementFormDefault="qualified">

  xs:complexType

    xs:sequence

     

        xs:complexType

          xs:sequence

           

           

            minOccurs="0" maxOccurs="5"/>

         

       

     

   

 


Group Indicators

Group indicators are used to define related sets of elements.

Element Groups

Element groups are defined with the group declaration:

...

You must define an all, choice, or sequence element inside the group declaration. The following example defines a group named "persongroup", which defines a set of elements that must appear in an exact order:

  xs:sequence

   

   

   

 

After you have defined the group, you can reference it in another definition:

  xs:sequence

   

   

   

 

  xs:sequence

   

   

 

Attribute Groups

Attribute groups are defined with the attributeGroup declaration:

...

The following example defines an attribute group named "personattrgroup":

 

 

 

After you have defined the attribute group, you can reference it in another definition, like this:

 

 

 

  xs:complexType