XML Schema Tuto...login
XML Schema Tutorial
author:php.cn  update time:2022-04-20 14:13:02

XML Schema composite type – elements only


XSD Element-only


"Element-only" composite type element is an element that can only contain other elements.


The composite type only contains elements

The XML element, "person", only contains other elements:

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

You can define the "person" element in the schema like this:

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

Or you can give the complexType element a name and let "person " element's type attribute to reference this name (using this method, several elements can reference the same composite 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>

php.cn