# XSD Empty Elements

A complex element with no contents, but only attributes is called an empty complex element.

### Complex Empty Elements:

Example 1:

<student marks="100"></student>

Explanation:

In the above example, the “student” element has no content at all.

Example 2:

<xs:element name="student"> <xs:complextype> <xs:complexcontent> <xs:restriction base="xs:integer"> <xs:attribute name="marks" type="xs:positiveInteger"></xs:attribute> </xs:restriction> </xs:complexcontent> </xs:complextype> </xs:element>

Explanation:

In the above example, a complex type is defined with complex content. A type that allows elements in its content must be defined to define a type with no content. However, no elements are declared. To signal that the intention is to restrict or extend the content model of a complex type, and the restriction of integer declares one attribute but does not introduce any element content, the complex content element is used.

Example 3:

<xs:element name="student"> <xs:complextype> <xs:attribute name="marks" type="xs:positiveInteger"></xs:attribute> </xs:complextype> </xs:element>

Explanation:

In the above example, we are declaring the “student” element more compactly.

Example 4:

<xs:element name="student" type="stdtype"></xs:element>   <xs:complextype name="stdtype"> <xs:attribute name="marks" type="xs:positiveInteger"></xs:attribute> </xs:complextype>

Explanation:

The complex Type element can also be provided with a name. It means that the “student” element can have a type attribute to refer to the name of the complexType. Several elements can refer to the same complex type by using this method.