XSD Elements Only

A complex type element containing an element that contains only other elements is called an “elements-only” complex type.

Complex Types Containing Elements Only:

Example 1:

<student>
  <firstname>Tom</firstname>
  <lastname>Davis</lastname>
</student>

Explanation:

In the above example, the XML element “student”, contains other elements only.

Example 2:

<xs:element name="student">
  <xs:complextype>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"></xs:element>
      <xs:element name="lastname" type="xs:string"></xs:element>
    </xs:sequence>
  </xs:complextype>
</xs:element>

Explanation:

In the above example, we are defining the “student” element in a schema. To indicate that the elements defined (“firstname” and “lastname”) must appear in that order inside a “student” element, we are using the <xs:sequence> tag.

Example 3:

<xs:element name="student" type="stdtype"></xs:element>
 
<xs:complextype name="stdtype">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"></xs:element>
    <xs:element name="lastname" type="xs:string"></xs:element>
  </xs:sequence>
</xs:complextype>

Explanation:

In the above example, we are providing a name to the complexType element. The “student” element is thus allowed to have a type attribute that refers to the name of the complexType. Several elements can refer to the same complex type, by using this method.

Please Share