<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:cablelabs:safi:xsd:com:3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="urn:cablelabs:safi:xsd:com:3.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 3.0.-1</b>
            <b>Controlled by specification: OC-SP-SaFI-COMv3.0-xxxxx</b>
        </xs:documentation>
    </xs:annotation>

    <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. Implementations using this in place of xs:string MUST NOT leave
		required attribute or element content empty. Whitespace-only content MAY be used.</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:</b> As opposed to xs:nonNegativeInteger, which derives from
		Integer, NonNegativeIntType derives from xs:int, which has a much smaller domain.</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 MUST be unique over all time. For all
		interoperable use, this MUST be 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 can be under namespace control, so the length MAY be less than 22, but MUST be
		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 characterizes an application according to the
		specification format, and the OrgID,AppID,version identify a specific expression of that repository template held in the
		application 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. Implementations SHOULD use appVerMajor and appVerMinor instead.</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 an interval starting at some instant. The instant is offset from some event, usually
		the 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 defines some instant, or an 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 (such as a 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:anyURI"/>
        
    </xs:simpleType>
    <xs:simpleType name="UuidUrlType">
        <xs:annotation>
            <xs:documentation>
                <p>UUID is a 16-byte integer, encoded using RFC 4122 Base64-URL form. This encodes to <tt>ceiling((bytes)/3)*4 = 24</tt> Base64 bytes
		less padding, or 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 response to a poll, RFI, and so on. 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, which 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 the lowest compatible schema version number (assumes all forward compatible within MajorVersion). A document
		with a minSchemaVersion of 2 MUST be 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="3"/>
        <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="3"/>
        <xs:attribute name="minSchemaMinorVersion" type="xs:int" use="optional" default="-1"/>
    </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 a ZIP Code or a 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>
