<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:o="http://www.w3.org/ns/odrl/2/" version="2.2"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/ns/odrl/2/"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:annotation>
        <xs:documentation> This is the XML Schema for ODRL Version 2.2 Working Draft Copyright ©
            2016 W3C (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules
            apply. </xs:documentation>
    </xs:annotation>
    <xs:element name="Policy" type="o:Policy"/>
    <xs:complexType name="Policy">
        <xs:choice minOccurs="1" maxOccurs="unbounded">
            <xs:element ref="o:asset" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:party" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:action" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:permission" minOccurs="0" maxOccurs="unbounded"/>  <!--Required Element (if no prohibition/obligation) -->
            <xs:element ref="o:prohibition" minOccurs="0" maxOccurs="unbounded"/> <!--Required Element (if no permission/obligation) -->
            <xs:element ref="o:obligation" minOccurs="0" maxOccurs="unbounded"/> <!--Required Element (if no permission/prohibition) -->
            <xs:element ref="o:constraint" minOccurs="0" maxOccurs="unbounded"/>
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute name="uid" type="xs:anyURI" use="required"/>
        <xs:attribute name="type" type="xs:anyURI" use="required"/>
        <xs:attribute name="conflict" type="o:ConflictTerm"/>
        <xs:attribute name="inheritFrom" type="xs:anyURI"/>
        <xs:attribute name="profile" type="xs:anyURI"/> <!--Required Attribute (when using ODRL Profile) -->
        <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>

    <xs:element name="permission" type="o:Permission"/>
    <xs:complexType name="Permission">
        <xs:choice minOccurs="1" maxOccurs="unbounded">
            <xs:element ref="o:asset" maxOccurs="unbounded"/> <!--Required Element -->
            <xs:element ref="o:action" maxOccurs="unbounded"/> <!--Required Element -->
            <xs:element ref="o:constraint" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:party" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:duty" minOccurs="0" maxOccurs="unbounded"/>
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>

    <xs:element name="prohibition" type="o:Prohibition"/>
    <xs:complexType name="Prohibition">
        <xs:choice minOccurs="1" maxOccurs="unbounded">
            <xs:element ref="o:asset" maxOccurs="unbounded"/>  <!--Required Element -->
            <xs:element ref="o:action" maxOccurs="unbounded"/> <!--Required Element -->
            <xs:element ref="o:constraint" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:party" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:remedy" minOccurs="0" maxOccurs="unbounded"/>
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>
    
    <xs:element name="obligation" type="o:Duty"/>
    <xs:element name="consequence" type="o:Duty"/>
    <xs:element name="remedy" type="o:Duty"/>
    <xs:element name="duty" type="o:Duty"/>
    <xs:complexType name="Duty">
        <xs:choice minOccurs="1" maxOccurs="unbounded">
            <xs:element ref="o:action" minOccurs="0"/>          <!--Required Element-->
            <xs:element ref="o:asset" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:constraint" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:party" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:consequence" minOccurs="0" maxOccurs="unbounded"/>
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute name="uid" type="xs:anyURI "/>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>

    <xs:element name="asset" type="o:Asset"/>
    <xs:complexType name="Asset">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="refinement" type="o:Constraint" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute name="uid" type="xs:anyURI"/>   <!--Required Attribute-->
        <xs:attribute name="relation" type="xs:anyURI"/>   <!--Required Attribute-->
        <xs:attribute name="partOf" type="xs:anyURI"/>
        <xs:attribute name="source" type="xs:anyURI"/>
        <xs:attribute name="type" type="xs:anyURI"/>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>

    <xs:element name="party" type="o:Party"/>
    <xs:complexType name="Party">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="refinement" type="o:Constraint" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute name="uid" type="xs:anyURI"/>   <!--Required Attribute-->
        <xs:attribute name="function" type="xs:anyURI"/>  <!--Required Attribute-->
        <xs:attribute name="partOf" type="xs:anyURI"/>
        <xs:attribute name="source" type="xs:anyURI"/>
        <xs:attribute name="type" type="xs:anyURI"/>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>

    <xs:element name="action" type="o:Action"/>
    <xs:complexType name="Action">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="refinement" type="o:Constraint" minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
        <xs:attribute name="name" type="xs:anyURI"/>    <!--Required Attribute-->
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>

    <xs:element name="constraint" type="o:Constraint"/>
    <xs:complexType name="Constraint">
        <xs:attribute name="name" type="o:URIorIDREF"/>    <!--leftOperand - Required Attribute-->
        <xs:attribute name="operator" type="xs:anyURI"/>  <!--Required Attribute-->
        <xs:attribute name="rightOperand" type="o:listOfValues"/>  <!--Required Attribute (if no rightOperandReference)-->
        <xs:attribute name="rightOperandReference" type="xs:anyURI"/>  <!--Required Attribute (if no rightOperand)-->
        <xs:attribute name="dataType" type="xs:anyURI"/>
        <xs:attribute name="unit" type="xs:anyURI"/>
        <xs:attribute name="status" type="xs:string"/>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>

    <xs:simpleType name="listOfValues">
        <xs:list itemType="xs:string"/>
    </xs:simpleType>
    
    <xs:simpleType name="URIorIDREF">
        <xs:union memberTypes="xs:anyURI xs:IDREF"/>
    </xs:simpleType>

    <xs:simpleType name="ConflictTerm">
        <xs:restriction base="xs:string">
            <xs:enumeration value="http://www.w3.org/ns/odrl/2/perm"/>
            <xs:enumeration value="http://www.w3.org/ns/odrl/2/prohibit"/>
            <xs:enumeration value="http://www.w3.org/ns/odrl/2/invalid"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:attributeGroup name="idAttributes">
        <xs:attribute name="id" type="xs:ID"/>
        <xs:attribute name="idref" type="xs:IDREF"/>
        <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:attributeGroup>
</xs:schema>
