<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://www.microsoft.com/sql/slp/Package.xsd" xmlns="http://www.microsoft.com/sql/slp/Package.xsd" xmlns:pkg="http://www.microsoft.com/sql/slp/Package.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:import namespace="http://www.microsoft.com/sql/setup/chainer/2007/04" id="chain" schemaLocation="..\..\Chainer\Workflow\ChainerSequence.xsd" />
  <xs:import namespace="http://www.microsoft.com/sql/setup/extension/2007/04" id="setup" schemaLocation="..\..\Extensions\Setup\SetupExtensionSchema.xsd" />
  <xs:import namespace="http://www.microsoft.com/sql/setup/bootstrap/2008/11" id="bootstrap" schemaLocation="..\..\Extensions\Bootstrap\BootstrapExtensionSchema.xsd" />
  <xs:import namespace="http://www.microsoft.com/sql/setup/extensioncommon/2008/11" id="common" schemaLocation="..\..\Extensions\ExtensionCommon\ExtensionCommonSchema.xsd" />
  <xs:import namespace="http://www.microsoft.com/sql/setup/msi/2008/11" id="msi" schemaLocation="..\..\Extensions\Msi\MsiExtensionSchema.xsd" />
  <xs:import namespace="http://www.microsoft.com/sql/setup/scoextension/2008/11" id="sco" schemaLocation="..\..\Extensions\ScoExtension\ScoExtensionSchema.xsd " />
  <xs:import namespace="http://www.microsoft.com/sql/setup/packagechainer/2010/05" id="package" schemaLocation="..\..\Extensions\MSI\PackageChainerExtensionSchema.xsd" />
  <xs:annotation>
    <xs:documentation>
        This document describes the schema for the chainer package XML.  This XML is generated
        at build time and added to a package containing an installer.  There are several types
        of installers (RTM, Service Pack, Hotfix) that all use this XML.
        
        ISSUES LIST:
          * Currently the MSI, Configuration, and Upgrade extension data is at the root package
            level.  In order to generalize the package XML they should probably be moved to
            an extension subnode.

        @Owner: scottkon
    </xs:documentation>
  </xs:annotation>
  <!--
    Package is the top level element in the document.
  -->
  <xs:element name="Package">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Properties" type="pkg:PropertiesType" />
        <xs:element name="Datastore" type="pkg:DatastoreType" />
        <xs:element name="Extensions" type="pkg:ExtensionsType" />
        <xs:element name="MsiPatches" type="pkg:MsiPatchesType" minOccurs="0" />
        <xs:element name="RuleGroups" type="pkg:RuleGroupsType" />
        <xs:element name="Sequences" type="pkg:SequencesType" />
        <xs:any namespace="##other" processContents="lax">
          <xs:annotation>
            <xs:documentation>
              Extensibility point in the Package XML Schema.  Elements from other namespaces can be inserted into the document.
            </xs:documentation>
          </xs:annotation>
        </xs:any>
      </xs:choice>
    </xs:complexType>
    <!--
      Key Constraints for Extensions
      Every extension name must be in the extension list
    -->
    <xs:key name="ExtensionID">
      <xs:selector xpath=".//pkg:Extension" />
      <xs:field xpath="@Id" />
    </xs:key>
  </xs:element>
  <!--
    Name value attribute group
  -->
  <xs:attributeGroup name="NameValuePair">
    <xs:attribute name="Id" type="xs:string" use="required" />
    <xs:attribute name="Value" type="xs:string" use="required" />
  </xs:attributeGroup>
  <!--
    Property name value attribute group
  -->
  <xs:attributeGroup name="PropertyNameValuePair">
    <xs:attribute name="Id" type="xs:string" use="required" />
    <xs:attribute name="Value" type="xs:string" use="required" />
    <xs:attribute name="HideSummaryLog" type="xs:boolean" use="optional" />
  </xs:attributeGroup>
  <!--
    Package properties contain name/value pairs that specify build time variables.
  -->
  <xs:complexType name="PropertiesType">
    <xs:sequence>
      <xs:element name="Property" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attributeGroup ref="pkg:PropertyNameValuePair" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <!--
    Extension XML allows the registration of .NET assemblies with the chainer
  -->
  <xs:complexType name="ExtensionsType">
    <xs:sequence>
      <xs:element name="Extension" minOccurs="1" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="Id" type="xs:string" use="required"/>
          <xs:attribute name="Assembly" type="xs:string" use="required" />
          <xs:attribute name="Strongname" type="xs:string" use="optional" />
          <xs:attribute name="Path" type="xs:string" use="required" />
        </xs:complexType>
        <xs:unique name="ExtensionIdIsUnique">
          <xs:selector xpath="Extension"/>
          <xs:field xpath="@Id"/>
        </xs:unique>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!--
    RuleGroups type
  -->
  <xs:complexType name="RuleGroupsType">
    <xs:sequence>
      <xs:element name="RuleGroup" minOccurs="1" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Rule" minOccurs="1" maxOccurs="unbounded">
              <xs:complexType>
                <xs:attribute name="Id" type="xs:string" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
          <xs:attribute name="Id" type="xs:string" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <!--
    Sequences define chainer workflows
  -->
  <xs:complexType name="SequencesType">
    <xs:choice minOccurs="1" maxOccurs="unbounded">
      <xs:any namespace="http://www.microsoft.com/sql/setup/chainer/2007/04" processContents="lax">
        <xs:annotation>
          <xs:documentation>
            Extensibility point in the Package XML Schema.  Elements from other namespaces can be inserted into the document.
          </xs:documentation>
        </xs:annotation>
      </xs:any>
    </xs:choice>
  </xs:complexType>
  <!--
    Datastore defines a set of XML files to load into the datastore at startup
  -->
  <xs:complexType name="DatastoreType">
    <xs:sequence>
      <xs:element name="Object" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence />
          <xs:attribute name="Type" type="xs:string" use="required" />
          <xs:attribute name="Features" type="xs:string" use="required" />
          <xs:attribute name="Filename" type="xs:string" use="required"/>
          <xs:attribute name="SchemaFilename" type="xs:string" use="optional"/>
          <xs:attribute name="NamespacePrefix" type="xs:string" use="optional"/>
          <xs:attribute name="NamespaceUri" type="xs:string" use="optional"/>
          <xs:attribute name="Namespace" type="xs:string" use="optional"/>
          <xs:attribute name="ExtensionId" type="xs:string" use="optional"/>
          <xs:attribute name="ResouceNamespace" type="xs:string" use="optional"/>
          <xs:attribute name="DatastorePath" type="xs:string" use="optional"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <!--
    The MSP Package list contains the information needed to install patch MSPs.
    <MsiPatches> and <MsiPatch> are new elements. When you generate the data structure "package.cs"
    by running generatecs.bat, make sure you also add the mapping names in fixupconfig.ini as following:

        MsiPatchesType=MsiPatches
        MsiPatchesTypeMsiPatch=MsiPatch

    Without it, generatecs.bat would generate unmatched names, and XML deserialization would fail
    with error:

        "There is an error in XML document {1, 2}"
  -->
  <xs:complexType name="MsiPatchesType">
    <xs:sequence>
      <xs:element name="MsiPatch" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <!-- Id is the same value from Package.xml where it is specified in
               the node <MsiPackage Id="something">
          -->
          <xs:attribute name="Id" type="xs:string" use="required" />
          <!-- FileName is patch file name, e.g., "SqlRun_Sql.msp" -->
          <xs:attribute name="FileName" type="xs:string" use="required" />
          <!-- Path is the relative path under CD media, e.g., ".\InstallPatch" -->
          <xs:attribute name="Path" type="xs:string" use="required" />
          <xs:attribute name="DescriptionResourceId" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
