The Finished Schema
As mentioned before, the XML Schema describes the XML document structure by nesting all of the declarations for elements and attributes, so we now need to bring together all of our previous declarations into one document.
The overall structure looks like this:
schema: itinerary_declaration: ticket_declaration: -airline_declaration -flight_declaration -departing_declaration (attributes) -arriving_declaration (attributes) -seating_declaration (attributes) -miles_declaration -duration_declaration
That is the basic outline of how everything nests together. If we go through that list, replacing the placeholders with the actual declarations, we end up with the final XML Schema, as shown in Listing 3.3.
Listing 3.3 The XML Schema for the Airline Ticket Itinerary
<?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.w3.org/2001/XMLSchema"> <annotation> <documentation>A Simple Airline Ticket Itinerary XML Schema</documentation> </annotation> <element name="itinerary"> <complexType> <sequence> <element name="ticket" maxOccurs="unbounded"> <complexType> <sequence> <element name="airline" type="string"/> <element name="flight" type="string"/> <element name="departing"> <complexType> <attribute name="date" type="date" use="required"/> <attribute name="time" type="time" use="required"/> <attribute name="airport" type="string" use="required"/> <attribute name="gate" type="string" use="optional"/> </complexType> </element> <element name="arriving"> <complexType> <attribute name="date" type="date" use="required"/> <attribute name="time" type="time" use="required"/> <attribute name="airport" type="string" use="required"/> <attribute name="gate" type="string" use="optional"/> </complexType> </element> <element name="seating"> <complexType> <attribute name="class" type="string" use="required"/> <attribute name="seat" type="string" use="optional"/> </complexType> </element> <element name="miles" type="string"/> <element name="duration" type="string"/> </sequence> </complexType> </element> </sequence> </complexType> </element> </schema>
Now, based on that XML Schema we can produce a final XML document, which looks like Listing 3.4.
Listing 3.4 The XML Document for the Airline Ticket Itinerary, Including the XML Instance Tags Linking It to the XML Schema
<?xml version="1.0" encoding="UTF-8" ?> <itinerary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="itinerary.xsd"> <ticket> <airline>American</airline> <flight>4090</flight> <departing date="2001-04-01" time="06:45:00-05:00" airport="IND" gate="A20" /> <arriving date="2001-04-01" time="07:52:00-05:00" airport="ORD" gate="B64" /> <seating class="Coach" seat="D3"/> <miles>168</miles> <duration>1hr 7mn</duration> </ticket> </itinerary>