XSD Indicators

The way elements are to be used in documents with indicators can be controlled.

Indicators:

In XSD, there are seven indicators:

Order indicators:

  • All
  • Choice
  • Sequence

Occurrence indicators:

  • maxOccurs
  • minOccurs

Group indicators:

  • Group name
  • attributeGroup name

Order Indicators:

To define the order of the elements, the order indicators are used. The default value for maxOccurs and minOccurs for all “Order” and “Group” indicators (any, all, choice, sequence, group name, and group reference) is 1.

All Indicator:

To indicate that the child elements can appear in any order and that each child element must occur only once, the <all> indicator is used. The <minOccurs> indicator can be set to 0 or 1 and the <maxOccurs> indicator can only be set to 1 while using the <all> indicator.

Example:


  
    
      
      
    
  

Choice Indicator:

To define that either one child element or another can occur, the <choice> indicator is used.

Example:


  
    
      
      
    
  

Sequence Indicator:

To specify that the child elements must appear in a specific order, the <sequence> indicator is used.

Example:


   
    
      
      
    
  

Occurrence Indicators:

To define how often an element can occur, the occurrence indicators are used.

maxOccurs Indicator:

To define the maximum number of times an element can occur, the <maxOccurs> indicator is used.

Example:


  
    
      
      
    
  

Explanation:

In the above example, we are defining the “sibling_name” element to occur a minimum of one time, i.e., the default value for minOccurs is 1 and a maximum of ten times in the “student” element.

minOccurs Indicator:

To define the minimum number of times an element can occur, the <minOccurs> indicator is used.

Example:


  
    
      
      
    
  

Explanation:

In the above example, we are defining the “sibling_name” element to occur a minimum of zero times and a maximum of ten times in the “student” element.

maxOccurs=”unbounded” statement:

We can use the maxOccurs=”unbounded” statement to allow an element to appear an unlimited number of times.

Example:

XML File: Myfriends.xml:






  David Jonas
  Tom Jonas



  Kia Smith
  Jenny Smith
  Drake Smith
  Robert Smith
  Tina Smith



  Stefan Gilbert



Explanation:

In the above example, the XML file contains a root element named “students”. Three “student” elements are defined inside the root element, where each “student” element must contain a “full_name” element and it can contain up to five “sibling_name” elements.

Schema File: “friends.xsd”:





  
    
      
        
          
            
            
          
        
      
    
  



Group Indicators:

To define related sets of elements, the group indicators are used.

Element Groups:

The group declaration is used to define the element groups.

Syntax:


...

Inside the group declaration, we need to define an all, choice, or sequence element.

Example:


  
    
    
    
  

Explanation:

In the above example, we are defining a group named “studentgroup”. This group again defines a group of elements that must occur in an exact sequence.

Example:


  
    
    
    
  





  
    
    
  

Explanation:

In the above example, we are referencing the defined group in another definition.

Attribute Groups:

The attributeGroup declaration is used to define the attribute groups.

Syntax:


...

Example:


  
  
  

Explanation:

In the above example, we are defining an attribute group named “studentattrgroup”.

Example:


   
  
  



  
    
  

Explanation:

In the above example, we are referencing the defined attribute group in another definition.

Please follow and like us:
Content Protection by DMCA.com