Skip to main content

Understanding XML Schemas

An XML schema is a template for an XML file. The schema describes what elements the XML file can contain, what sub-elements it can contain, and constraints described in types and attributes. XML schemas can contain the following:

  • Elements
  • Children
  • Attributes
  • Common Types
  • Simple Types
  • Complex Types

The following is an example of a schema:

The plus symbol (+) shows that there are more parts under that tag, but the example is collapsed to show a small portion.

<?xml version="1.0" encoding="UTF-8" ?> 
<xs:schemaxmlns="http://www.website.com"xmlns:xs="http://www.website2.com" elementFormDefault="qualified">
  <xs:element name="OTA_AirLowFareSearchRQSchemaName">
     <xs:complexType>
       +<xs:sequence>
       +<xs:attributename="EchoToken"use="optional">
       +<xs:attribute name="TimeStamp" type="xs:string"use="optional">
       +<xs:attribute name="Target"use="optional"default="Production">
       +<xs:attribute name="Version" type="xs:string"use="required">
       +<xs:attribute name="SequenceNmbr"type="xs:string"use="optional">
       +<xs:attribute name="PrimaryLangID"type="xs:language" use="optional">
       +<xs:attribute name="AltLangID"type="xs:language"use="optional">
     </xs:complexType>
  </xs:element>
</xs:schema>

Elements

Elements are the main building blocks of XML files. The element definition within a schema must contain a name, which will appear in the final XML file. Elements can also contain types, simple types, and complex types that describe what can be contained within an element in the final XML file.

Elements must appear between start and end tags. In the following example, the bolded text shows the start and end tags. The content area shows the value for the element.

<name attribute="value">content</name>

XML provides special syntax for representing an element with empty content. Instead of a start tag followed immediately by an end tag, a document may contain an empty element tag. An empty-element tag resembles a start tag, but contains a forward slash (/) immediately before the closing angle bracket (>). The following example from the StructureFareRules response illustrates an element with empty content.

<EquivalentFare /> 

Children

Some elements or complex types contain child elements within the start and end tags. A child element is an element within an element. Multiple child elements are referred to as children. The following example from the response contains child elements (children).

<FlightSegment ArrivalDate="2013-09-20T15:00:00" BookingDate="2013-05-14T05:19:00" DepartureDate2013-09-20T12:00:00" FlightNumber="3" RealReservationStatus="SS"> ResBookDesigCode="Y"> ReservationStatus="OK"> SegmentNumber="01"> SegmentType="A">
    <DepartureAirport LocationCode="JFK" />
    <ArrivalAirport LocationCode="LAX" />
    <MarketingAirline Code="K0"
    <OperatingAirline Code="K0" />
</FlightSegment>

Attributes

Attributes provide extra information within an element. Attribute values are always between quotes ("value") and can appear only once in each element. In the following example, the italic text highlights the attribute. The value area shows the value for the attribute.

<name attribute="value">content</name>

Simple Types 

Simple types specify the constraints and information about the values of attributes or text-only elements. Simple types do not contain children.

The following example shows the AirportCodeType element (blue) from the request. This element contains the AirportCode attribute defined by AirportCodeType, which is simple. AirportCodeType provides the constraints on what you can enter for the AirportCode attribute.

<AirportCodeType AirportCode="1">

Common Types

Common types are simple types that apply to all the schemas present in this API's Resources tab.

Complex Types

Complex types contain other element definitions and describe which children an element can contain. Complex types can contain both children and attributes.

Following is a generic example. The POS element has the POS_Type, which is a complex type that describes what the POS element can contain. The POS_Type contains Source, which is a child element. The Source element also has a complex type that also contains children and attributes.

<POS>
 <Source PseudoCityCode="PCC0">
       <RequestorID Type="0.AAA.X "ID="
     REQ.ID">
            <CompanyName Code="CUSTOMER" />
       </RequestorID>
 </Source>
</POS>