XSD - Complex Empty Element


Advertisements


Complex Empty Element can only have attribute, but no content. See the following example −

<student rollno = "393" />

We can declare Complex Empty elements using the following methods −

Use type attribute

Define a complex type element "StudentType" and then create element student of type "StudentType".

<xs:complexType name = "StudentType">
   <xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>   
</xs:complexType>

<xs:element name = 'student' type = 'StudentType' />			 

Use ComplexContent

Define an element of complexType with complexContent. ComplexContent specifies that the content of the element is to be restricted.

<xs:element name = "student">
   <xs:complexType>
      <xs:complexContent>
         <xs:restriction base = "xs:integer">
            <xs:attribute name = "rollno" type = "xs:positiveInteger"/>
         </xs:restriction>
      </xs:complexContent>
   </xs:complexType>
</xs:element>		 

Use ComplexType alone

Define an element of complexType with required attribute element only.

<xs:element name = "student">
   <xs:complexType>
      <xs:attribute name = "rollno" type = "xs:positiveInteger"/>
   </xs:complexType>
</xs:element>


xsd_complex_types.htm
Advertisements