Xsd Indicators in XML
? XSD Indicators in XML Schema
In XSD (XML Schema Definition), indicators define the structure and occurrence rules of child elements within a complex type. They control how elements are ordered, how many may appear, and whether choices or groupings are used.
? Types of XSD Indicators
| Indicator | Purpose |
|---|---|
xs:sequence | Child elements must appear in exact order |
xs:choice | Only one of the child elements can appear |
xs:all | All child elements must appear, but in any order, once each |
? 1. xs:sequence — Ordered elements
XSD:
<xs:complexType> <xs:sequence> <xs:element name="firstName" type="xs:string"/> <xs:element name="lastName" type="xs:string"/> </xs:sequence></xs:complexType>? Valid XML:
<person> <firstName>John</firstName> <lastName>Doe</lastName></person>? Invalid (wrong order):
<person> <lastName>Doe</lastName> <firstName>John</firstName></person>? 2. xs:choice — Only one allowed
XSD:
<xs:complexType> <xs:choice> <xs:element name="email" type="xs:string"/> <xs:element name="phone" type="xs:string"/> </xs:choice></xs:complexType>? Valid:
<contact> <email>user@example.com</email></contact>? Invalid (both used):
<contact> <email>user@example.com</email> <phone>1234567890</phone></contact>? 3. xs:all — All required, any order
XSD:
<xs:complexType> <xs:all> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:all></xs:complexType>? Valid:
<location> <country>USA</country> <city>New York</city></location>? Also valid in the reverse order.
? Invalid (missing one):
<location> <city>New York</city></location>? Grouping Elements with Indicators
You can group indicators or nest them:
<xs:complexType> <xs:sequence> <xs:element name="id" type="xs:integer"/> <xs:choice> <xs:element name="email" type="xs:string"/> <xs:element name="phone" type="xs:string"/> </xs:choice> </xs:sequence></xs:complexType>? Summary Table
| Indicator | Allows Multiple? | Ordered? | Description |
|---|---|---|---|
xs:sequence | Yes | Yes | Child elements appear in defined order |
xs:choice | No (default) | N/A | Only one of the child elements can appear |
xs:all | No | No | All elements must appear, any order |
Would you like a full example combining all three indicators in one XML/XSD?