<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.cablelabs.com/namespaces/safi/xsd/com/2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.cablelabs.com/namespaces/safi/xsd/com/2.0"
    elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
    <xs:annotation>
        <xs:documentation><b>Copyright (C) 2008-2011, Cable Television Laboratories, Inc.</b>
            <b>SaFI Common XML Schema, Release Version 2.0.0</b>
            <b>Controlled by specification: OC-SP-SaFI-COMv2.0-110131</b>
        </xs:documentation>
    </xs:annotation>
    
    <!-- Simple types -->
    <xs:simpleType name="DerivativeIdType">
        <xs:annotation>
            <xs:documentation>
                <p>Derivative ID type. This can be a GUID represented in RFC 4122 Base64-URL form (so 16 bytes convert to a 22 byte string). This might use a more terse form, but some namespace resolution is needed first.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string"/>
    </xs:simpleType>
    <xs:simpleType name="EpsidType">
        <xs:annotation>
            <xs:documentation> 
                <p>Enhancement sequence number within a PEID. This is an xs:int with a domain of zero to 65,535 (two binary bytes). These sequence numbers are assigned to message-addressable nodes in the campaign description associated with PEIDs and ETypes. The PEID+EPSID can be used to locate the node, and its EType allows further navigation. EpsidType is limited to two binary bytes.</p> 
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="65535"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="EventIDType">
        <xs:annotation>
            <xs:documentation>
                <p>These numbers are processing identifiers assigned to message-addressable nodes in the campaign description, i.e, containing a PEID+EPSID. The PEID+EPSID can be used to locate the node, and its EType identifies specific message processing associated with that node. EventIdType is an xs:int with a domain of zero to 99.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
            <xs:maxInclusive value="99"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="nonEmptyStringType">
        <xs:annotation>
            <xs:documentation> 
                <p>A derivative of xs:string that is required to have content. Using this in place of xs:string precludes required attribute or element content being left empty. However, it does not preclude only whitespace content.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="nonNegativeIntType">
        <xs:annotation>
            <xs:documentation> 
                <p>This is an xs:int restricted to zero or positive content<b>Note: As opposed to xs:nonNegativeInteger, which derives from Integer, NonNegativeIntType derives from xs:int, which has a much smaller domain.</b></p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:int">
            <xs:minInclusive value="0"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="PeidType">
        <xs:annotation>
            <xs:documentation>
                <p>The indentifier of a CIP document message-addressable node.  This identifier is unique over all time.  For all interoperable use, this is an xs:string of 22 characters which contains a GUID represented in RFC 4122 Base64-URL form (so 16 bytes convert to a 22-byte string). For private use the PEID may be under namespace control, so the length may be less than 22, but non-zero.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:maxLength value="22"/>
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="PositiveIntType">
        <xs:annotation>
            <xs:documentation>
                <p>This is an xs:int restricted to  positive content </p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:int">
            <xs:minInclusive value="1"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="RepositoryAppKeyType">
        <xs:annotation>
            <xs:documentation>
                <p>This identifies a complete application. It is a key to access the application characterization in the application repository. </p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string"/>
    </xs:simpleType>
    <xs:attributeGroup name="ApplicationDefinitionAttributeGroup">
        <xs:annotation>
            <xs:documentation>
                <p>The attribute set for characterizing an application. The repositoryAppKey characterized an application according to the specification format, and the OrgID,AppID,version identify a specific expression of that repository template held in the pplication repository. AppId/orgId/appVer are a set, all present or absent. Either that set or appDataReverence or both must be present for the applicationDefinition to be valid.</p>
                <p>Note that appVer is to be deprecated in a future release. Use appVerMajor and appVerMinor.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="orgId" type="xs:string" use="optional"/>
        <xs:attribute name="appId" type="xs:string" use="optional"/>
        <xs:attribute name="appVer" type="xs:unsignedInt" use="optional"/>
        <xs:attribute name="appVerMajor" type="xs:unsignedInt" use="optional"/>
        <xs:attribute name="appVerMinor" type="xs:unsignedInt" use="optional"/>
        <xs:attribute name="appDataReference" type="RepositoryAppKeyType" use="optional"/>
    </xs:attributeGroup>
    <xs:attributeGroup name="RelativeTimeAttributeGroup">
        <xs:annotation>
            <xs:documentation>
                <p>Attribute set that defines some instant, or interval starting at some instant. The instant is offset from some event, usually start of flight (as xs:duration), and the interval is a duration after the offset.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="offset" type="xs:duration" use="required"/>
        <xs:attribute name="interval" type="xs:duration" use="optional"/>
    </xs:attributeGroup>
    <xs:attributeGroup name="OptionalRelativeTimeAttributeGroup">
        <xs:annotation>
            <xs:documentation>
                <p>Attribute set that may define some instant, or interval starting at some instant, but may also be empty. The instant is offset from some event defined by application convention (as xs:duration), and the interval is a duration after the offset.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="offset" type="xs:duration" use="optional"/>
        <xs:attribute name="interval" type="xs:duration" use="optional"/>
    </xs:attributeGroup>
    <xs:simpleType name="SyscodeType">
        <xs:annotation>
            <xs:documentation>
                <p>A syscode is a unique human-readable identifier that tends to represent an insertion point (ex. splicer). These system level syscodes are at the MSO level within a given market. Larger network areas are represented by a syscode that is itself composed of syscodes.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:maxLength value="4"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="UuidUrlType">
        <xs:annotation>
            <xs:documentation>
                <p>UUID is a 16 byte integer, encoded using RFC 4122 Base64-URL form, so encodes to ceiling((bytes)/3)*4 = 24 Base64 bytes less padding, so 22 total. It would be about 43 decimal, or 32 hex digits.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:length value="22"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="ZipcodeType">
        <xs:annotation>
            <xs:documentation>
                <p>A US Postal zip code in either five digit or five plus four digit notation</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="(\d{5}-\d{4})|(\d{5})"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="UserInputType">
        <xs:annotation>
            <xs:documentation>
                <p>UserInput is a string used to store a user's selection to a poll, RFI, etc.. This element is optional as it will not be included in messages representing Service Metric updates.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string"/>
    </xs:simpleType>
    <xs:simpleType name="ParametersType">
        <xs:annotation>
            <xs:documentation>
                <p>An optional unconstrained xs:string used to pass other relevant data.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string"/>
    </xs:simpleType>
    <xs:simpleType name="PhoneNumberType">
        <xs:annotation>
            <xs:documentation> 
                <p>Human-readable contact phone, so may have extension, etc. Not expected to be machine processable.</p> </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:maxLength value="25"/>
        </xs:restriction>
    </xs:simpleType>

    <!-- Complex types -->
    <xs:complexType name="VersionType">
        <xs:annotation>
            <xs:documentation>
                <p>Major version provides the macro versioning number for each interface.  Versions containing the same major version should provide backwards compatibility.</p>
                <p>The MinSchemaVersion should refer to a MajorVersion number.</p>
                <p>MinorVersion, when positive, starts at one and identifies incremential and backwards compatible updates to a major version. Minor version numbers which are negative ordinals, starting at -1 and decreasing, identify development versions derived from the referenced major version but which are otherwise completely independent.</p>
                <p>MicroVersion is negative ordinals starting at -1 for ReleaseCandidates, and non-negative ordinals starting at 0 for releases.  Assumed to be zero if omitted.</p> 
                <p>MinSchemaVersion is lowest compatible schema version number (assumes all forward compatible within MajorVersion) A document with a minSchemaVersion of 2 is compatible with any processor implementing schema version 2 or higher, but not with a processor implementing schema 1.</p>
                <p>MinSchemaMinorVersion is the lowest compatible schema minor version number.  If missing, all minor version numbers are assumed to be compatible. </p>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="majorVersion" type="PositiveIntType" fixed="2"/>
        <xs:attribute name="minorVersion" type="xs:int" fixed="0"/>
        <xs:attribute name="microVersion" type="xs:int" use="optional"/>
        <xs:attribute name="minSchemaVersion" type="PositiveIntType" default="2"/>
        <xs:attribute name="minSchemaMinorVersion" type="xs:int" use="optional" default="0"/>
    </xs:complexType>
    <xs:complexType name="ExtType"> 
        <xs:annotation>
            <xs:documentation>
                <p>Extensibility - provides for elements from any namespace.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:anyAttribute namespace="##any" processContents="lax"/>
    </xs:complexType>

    <xs:complexType name="GeographicCodeType">
        <xs:annotation>
            <xs:documentation>
                <p>GeographicCode is an identifier used to denote the location of the device/unit. This could be zipcode or syscode.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:choice>
            <xs:element name="Syscode" type="SyscodeType"/>
            <xs:element name="Zipcode" type="ZipcodeType"/>
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="ReportDataType">
        <xs:annotation>
            <xs:documentation>
                <p>A name-value pair report data set</p>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="value" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="AcknowledgementMessageType">
        <xs:sequence>
            <xs:element name="Ack" type="xs:boolean"/>
        </xs:sequence>
        <xs:attribute name="transmissionId" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="TrackingType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:anyAttribute namespace="##any" processContents="lax"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="TimestampType">
        <xs:sequence>
            <xs:element name="StartTime" type="xs:dateTime"/>
        </xs:sequence>
        <xs:attributeGroup ref="RelativeTimeAttributeGroup"/>
    </xs:complexType>


    <xs:complexType name="TimeRangeType">
        <xs:annotation>
            <xs:documentation>
                <p>Defines an absolute time range.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="starttime" type="xs:dateTime" use="required"/>
        <xs:attribute name="endtime" type="xs:dateTime" use="required"/>
    </xs:complexType>


    <xs:complexType name="FaultType">
        <xs:annotation>
            <xs:documentation>
                <p>Defines a standard fault model for the SaFI web services.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="Reason" type="xs:string"/>
        </xs:sequence>
        <xs:attribute name="code" type="xs:int" use="optional"/>
    </xs:complexType>

    <!-- Groups -->
    <xs:group name="PackageIDGroup">
        <xs:annotation>
            <xs:documentation>
                <p>Contains identifiers used to unambiguously identify a stewarded package.</p>
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="PEID" type="PeidType"/>
            <xs:element name="EPSID" type="EpsidType"/>
            <xs:element name="EventID" type="EventIDType" minOccurs="0"/>
        </xs:sequence>
    </xs:group>
</xs:schema>
