<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:annotation>
        <xs:documentation xml:lang="en">
        xmltv-lineups schema for XMLTV Project
        Copyright Nick Morrott, 2011,2012
        </xs:documentation>
    </xs:annotation>

    <xs:element name="xmltv-lineups" type="xmltvLineupsType" />

    <xs:complexType name="xmltvLineupsType">
        <xs:sequence>
            <xs:element name="xmltv-lineup" type="xmltvLineupType" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attributeGroup ref="sourceGeneratorAttrs" />
    </xs:complexType>

    <xs:complexType name="xmltvLineupType">
        <xs:sequence>
            <xs:element name="type"         type="lineupTypeEnum" />
            <xs:element name="display-name" type="strWithLangAttrType" maxOccurs="unbounded" />
            <xs:element name="logo"         type="logoType"            minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="availability" type="availabilityType"    minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="lineup-entry" type="lineupEntryType"     minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="id" type="xs:string" />
        <xs:attributeGroup ref="sourceGeneratorAttrs" />
    </xs:complexType>

    <xs:complexType name="lineupEntryType">
        <xs:sequence>
            <xs:element name="preset"       type="xs:string"           minOccurs="0" />
            <xs:element name="section"      type="xs:string"           minOccurs="0" />
            <xs:element name="package"      type="strWithTypeAttrType" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="availability" type="availabilityType"    minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="station"      type="stationType" />

            <xs:choice>
                <xs:element name="dvb-channel"    type="dvbChanType"    minOccurs="0" maxOccurs="unbounded" />
                <xs:element name="stb-channel"    type="stbChanType"    minOccurs="0" maxOccurs="unbounded" />
                <xs:element name="iptv-channel"   type="iptvChanType"   minOccurs="0" maxOccurs="unbounded" />
                <xs:element name="analog-channel" type="analogChanType" minOccurs="0" maxOccurs="unbounded" />
            </xs:choice>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="stationType">
        <xs:sequence>
            <xs:element name="name"            type="strWithLangAttrType" />
            <xs:element name="short-name"      type="strWithLangAttrType" minOccurs="0" />
            <xs:element name="logo"            type="logoType"            minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="commercial-free" type="xs:boolean"          minOccurs="0" />
            <xs:element name="video"           type="videoType"           minOccurs="0" />
            <xs:element name="audio"           type="audioType"           minOccurs="0" />
        </xs:sequence>
        <xs:attributeGroup ref="rfc2838" />
        <xs:attribute name="type" type="stationTypeEnum" />
    </xs:complexType>

    <xs:complexType name="videoType">
        <xs:sequence>
            <xs:element name="format"       type="xs:string" minOccurs="0" />
            <xs:element name="aspect-ratio" type="xs:string" minOccurs="0" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="audioType">
        <xs:sequence>
            <xs:element name="format"       type="xs:string" minOccurs="0" />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="dvbChanType">
        <xs:sequence>
            <xs:element name="original-network-id" type="xs:integer" />
            <xs:element name="transport-id"        type="xs:integer" minOccurs="0" />
            <xs:element name="service-id"          type="xs:integer" />
            <xs:element name="lcn"                 type="xs:string"  minOccurs="0" />
            <xs:element name="service-name"        type="xs:string"  minOccurs="0" />
            <xs:element name="provider-name"       type="xs:string"  minOccurs="0" />
            <xs:element name="encrypted"           type="xs:boolean" minOccurs="0" />
        </xs:sequence>
        <xs:attributeGroup ref="rfc2838" />
    </xs:complexType>

    <xs:complexType name="stbChanType">
        <xs:sequence>
            <xs:element name="stb-preset" type="xs:string" />
        </xs:sequence>
        <xs:attributeGroup ref="rfc2838" />
    </xs:complexType>

    <xs:complexType name="iptvChanType">
        <xs:sequence>
            <xs:element name="iptv-url" type="xs:string" />
            <xs:element name="port"     type="xs:integer" />
        </xs:sequence>
        <xs:attributeGroup ref="rfc2838" />
    </xs:complexType>

    <xs:complexType name="analogChanType">
        <xs:sequence>
            <xs:element name="system"       type="xs:string" />
            <xs:element name="number"       type="xs:string" />
            <xs:element name="frequency"    type="xs:integer" minOccurs="0" />
            <xs:element name="fcc-callsign" type="xs:string"  minOccurs="0" />
            <xs:element name="cni">
                <xs:complexType>
                    <xs:attribute name="tt-8-30-1" type="xs:string" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attributeGroup ref="rfc2838" />
    </xs:complexType>

    <xs:simpleType name="lineupTypeEnum">
        <xs:restriction base="xs:string">
            <xs:enumeration value="DTV"/>
            <xs:enumeration value="STB"/>
            <xs:enumeration value="IPTV"/>
            <xs:enumeration value="Analog"/>
            <xs:enumeration value="List"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="stationTypeEnum">
        <xs:restriction base="xs:string">
            <xs:enumeration value="TV"/>
            <xs:enumeration value="Radio"/>
            <xs:enumeration value="Data"/>
            <xs:enumeration value="Text service"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="strWithLangAttrType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="lang" type="xs:language" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="strWithTypeAttrType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="type" type="xs:string" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="availabilityType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="area" type="availabilityAreaEnum" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="availabilityAreaEnum">
        <xs:restriction base="xs:string">
            <xs:enumeration value="country"/>
            <xs:enumeration value="region"/>
            <xs:enumeration value="city"/>
            <xs:enumeration value="postcode"/>
            <xs:enumeration value="transmitter"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="logoType">
        <xs:attribute name="url"    type="xs:string" />
        <xs:attribute name="height" type="xs:integer" />
        <xs:attribute name="width"  type="xs:integer" />
    </xs:complexType>

    <xs:attributeGroup name="sourceGeneratorAttrs">
        <xs:attribute name="modified"            type="xs:string" />
        <xs:attribute name="source-info-name"    type="xs:string" />
        <xs:attribute name="source-info-url"     type="xs:string" />
        <xs:attribute name="source-data-url"     type="xs:string" />
        <xs:attribute name="generator-info-name" type="xs:string" />
        <xs:attribute name="generator-info-url"  type="xs:string" />
    </xs:attributeGroup>

    <xs:attributeGroup name="rfc2838">
        <xs:attribute name="rfc2838" type="xs:string" />
    </xs:attributeGroup>

</xs:schema>
