-- Not Only Learning Technology, But Also Dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Bookmarks
XML Schema Tutorial
- XML Schema Tutorial
- XML Schema Introduction
- Why Use XML Schema?
- How to Use XML Schema
- XML Schema Element
- XSD Simple Elements
- XML Schema Attributes
- XML Schema Facets
- XML Schema Complex Elements
- XML Schema Complex Empty Elements
- XML Schema Complex Types - Element-Only
- XML Schema Complex Elements - Text-Only
- XML Schema Complex Types - Mixed Content
- XML Schema Indicators
- XML Schema any Element
- XML Schema anyAttribute Element
- XML Schema Element Substitution
- XML Schema Example
- XML Schema String Data Types
- XML Schema Date/Time Data Types
- XML Schema Numeric Data Types
- XML Schema Miscellaneous Data Types
- XML Editor
- XML Schema Summary
- XML Schema Reference Manual
XSD Element-Only
"Element-only" complex type elements are elements that can only contain other elements.
Complex Type Containing Only Elements
The XML element "person" contains only 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>
Notice the <xs:sequence>. It means that the defined elements must appear in the "person" element in the order shown above.
Or you can give the complexType element a name and let the "person" element's type attribute reference that name (using this method, several elements can reference 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>
YouTip