Latest web development tutorials

XML Schema complex type - contain only elements

"Element containing only" complex type element is the only element that contains other elements.


Complex type contains only elements

XML element, "person", contain only other elements:

<person>
<firstname>John</firstname>
<lastname>Smith</lastname>
</person>

You can define "person" element in the schema:

<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>

Please pay attention to this . It means that the element must be defined according to the above order of appearance in the "person" element.

Or you can set a name for the complexType element, and let the type attribute "person" element to reference this name (such as the use of this method, several elements can refer to the same complex type):

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

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