How to use XSD Indicators in XML

In this article I am going to explain about XSD Indicators in XML.
  • 4619

XSD Indicators in XML

XSD Indicators use for control how element are use in document. There are three category of Indicators. In three category seven type of indicator.

Order Indicator

Order Indicators use for define order of element in document.

(1) All :- The Indicators defined the element can be appears in any order. And each element must occurs only one.

<xs:element name="EmpDetail">

  <xs:complexType>

    <xs:all>

      <xs:element name="Name" type="xs:string"/>

      <xs:element name="Address" type="xs:string"/>

    </xs:all>

  </xs:complexType>

</xs:element>

(2) Choice :- The Choice Indicators defined either one child element can be occurs or other can be occurs.

<xs:element name="EmpDetail">

  <xs:complexType>

    <xs:choice>

      <xs:element name="Employee" type="Employee"/>

      <xs:element name="Member" type="Member"/>

    </xs:choice>

  </xs:complexType>

</xs:element>

 

(3) Sequence :- The Sequence Indicators defined that child element must be appears in specifics order.

 

<xs:element name="Employee">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="Name" type="xs:string"/>

      <xs:element name="Address" type="xs:string"/>

    </xs:sequence>

  </xs:complexType>

</xs:element>

 

Occurrence Indicators

 

Occurrence Indicators use for define hoe element occurs often.

 

(4) minOccurs :- minOccurs Indicator defined an element can be occurs at minimum number time.

 

<xs:element name="Employee">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="Name" type="xs:string"/>

      <xs:element name="Address" type="xs:string"

      maxOccurs="50" minOccurs="5"/>

    </xs:sequence>

  </xs:complexType>

</xs:element>

 

(5) maxOccurs :- maxOccurs Indicators defined an element can be occurs at maximum number time. // In this example element will occurs minimum one time and maximum 55 time.

 

<xs:element name="Employee">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="Name" type="xs:string"/>

      <xs:element name="Fname" type="xs:string" maxOccurs="55"/>

    </xs:sequence>

  </xs:complexType>

</xs:element>

 

To allow element to appears unlimited number of time we use 'maxOccurs="unbounded"'.

 

Group Indicators

 

Group Indicators use for define related of set element.

 

(6) Element Group :- Element group Indicators use for defined with group declaration.

 

<xs:group name="StudentGroup">

  <xs:sequence>

    <xs:element name="Name" type="xs:string"/>

    <xs:element name="Class" type="xs:string"/>

    <xs:element name="Dob" type="xs:date"/>

  </xs:sequence>

</xs:group>

 

Defined reference its group in another definition.

 

<xs:group name="StudentGroup">

  <xs:sequence>

    <xs:element name="Name" type="xs:string"/>

    <xs:element name="Class" type="xs:string"/>

    <xs:element name="Dob" type="xs:date"/>

  </xs:sequence>

</xs:group>

 

<xs:element name="Student" type="StuInfo"/>

 

<xs:complexType name="StuInfo">

  <xs:sequence>

    <xs:group ref="StudfentGroup"/>

    <xs:element name="Name" type="xs:string"/>

  </xs:sequence>

</xs:complexType>

 

(7) Attribute Group :- Attribute group Indicator use for defined with Attribute group declaration.

 

<xs:attributeGroup name="StudentGroup">

  <xs:attribute name="Name" type="xs:string"/>

  <xs:attribute name="Class" type="xs:string"/>

  <xs:attribute name="Dob" type="xs:date"/>

</xs:attributeGroup>

 

Defined reference its group in other definition.

 

<xs:attributeGroup name="StudentGroup">

  <xs:attribute name="Name" type="xs:string"/>

  <xs:attribute name="Class" type="xs:string"/>

  <xs:attribute name="Dob" type="xs:date"/>

</xs:attributeGroup>

 

<xs:element name="Student">

  <xs:complexType>

    <xs:attributeGroup ref="StudentGroup"/>

  </xs:complexType>

</xs:element>

 

Further Readings

You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

 

© 2020 DotNetHeaven. All rights reserved.