The best XML Schema indicator Tutorial In 2024, In this tutorial you can learn Indicator,Order indicator,Occurrence indicator,Group indicator,

XML Schema indicator

By the indicator, we can control the use of the elements in the document mode.


Indicator

There are seven indicators:

Order indicators:

  • All
  • Choice
  • Sequence

Occurrence indicator:

  • maxOccurs
  • minOccurs

Group indicator:

  • Group name
  • attributeGroup name

Order indicator

Order indicators are used to define the order of the elements.

All indicator

<All> indicator in accordance with the provisions of sub-elements can appear in any order, and each child element must appear only once:

<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>

Note: When using the <all> indicator, you can put <minOccurs> is set to 0 or 1, but only the <maxOccurs> indicator is set to 1 (later explain <minOccurs> and <maxOccurs>).

Choice Indicator

<Choice> indicator provides for a sub-element occur or may occur another child element (or the other):

<xs:element name="person">
<xs:complexType>
<xs:choice>
<xs:element name="employee" type="employee"/>
<xs:element name="member" type="member"/>
</xs:choice>
</xs:complexType>
</xs:element>

Sequence Indicator

<Sequence> child element must be specified in a specific order:

<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>


Occurrence indicator

Occurrence indicators are used to define the frequency of an element occur.

Note: For all of the "Order" and "Group" indicator (any, all, choice, sequence , group name and group reference), which maxOccurs and minOccurs defaults are 1.

maxOccurs indicator

<MaxOccurs> indicator can specify the maximum number of times an element can occur:

<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string" maxOccurs="10"/>
</xs:sequence>
</xs:complexType>
</xs:element>

The above examples show that the child element "child_name" may appear in the least "person" element once (where the default value of minOccurs is 1), appears at most 10 times.

minOccurs indicator

<MinOccurs> indicator may require a minimum number of times an element can occur:

<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string"
maxOccurs="10" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>

The above examples show that the child element "child_name" there may be a minimum of 0 in "person" element, appears at most 10 times.

Tip: To make the number of occurrences of an element is not limited, please use the maxOccurs = "unbounded" this statement:

A practical example:

Called "Myfamily.xml" XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>

<persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="family.xsd">

<person>
<full_name>Hege Refsnes</full_name>
<child_name>Cecilie</child_name>
</person>

<person>
<full_name>Tove Refsnes</full_name>
<child_name>Hege</child_name>
<child_name>Stale</child_name>
<child_name>Jim</child_name>
<child_name>Borge</child_name>
</person>

<person>
<full_name>Stale Refsnes</full_name>
</person>

</persons>

Above this XML file contains a root element named "persons" of. Inside this root element, we have defined three "person" element. Each "person" element must contain a "full_name" elements, but it may contain up to 5 "child_name" element.

This is the schema file "family.xsd":

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

<xs:element name="persons">
<xs:complexType>
<xs:sequence>
<xs:element name="person" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string"
minOccurs="0" maxOccurs="5"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>


Group indicator

Group indicator for several batches of elements related to the definition.

Element Group

Element group defined by the group declared:

<xs:group name="groupname">
/en.
</xs:group>

You must define a statement within the group all, choice or sequence elements. The following example defines a group named "persongroup", which defines a set of elements that must be present according to a precise order:

<xs:group name="persongroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:group>

After you have defined the group is completed, you can refer to it in another definition of:

<xs:group name="persongroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:group>

<xs:element name="person" type="personinfo"/>

<xs:complexType name="personinfo">
<xs:sequence>
<xs:group ref="persongroup"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>

Property group

Attribute groups defined by attributeGroup statement:

<xs:attributeGroup name="groupname">
/en.
</xs:attributeGroup>

The following example defines a property group named "personattrgroup" of:

<xs:attributeGroup name="personattrgroup">
<xs:attribute name="firstname" type="xs:string"/>
<xs:attribute name="lastname" type="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>

After you have defined a complete set of attributes, you can reference it in another definition, like so:

<xs:attributeGroup name="personattrgroup">
<xs:attribute name="firstname" type="xs:string"/>
<xs:attribute name="lastname" type="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>

<xs:element name="person">
<xs:complexType>
<xs:attributeGroup ref="personattrgroup"/>
</xs:complexType>
</xs:element>
XML Schema indicator
10/30