<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:o="http://w3.org/ns/odrl/2/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://w3.org/ns/odrl/2/" elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:element name="policy" type="o:policyCT"/>
    <xs:complexType name="policyCT">
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                    <xs:element ref="o:permission" minOccurs="0" maxOccurs="unbounded"/>
                    <xs:element ref="o:prohibition" minOccurs="0" maxOccurs="unbounded"/>
                    <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
                <xs:attribute name="uid" type="o:URIQnameQcode" use="required"/>
                <xs:attribute name="type" type="o:URIQnameQcode" use="required"/>
                <xs:attribute name="conflict" type="o:conflictENUM"/>
                <xs:attribute name="undefined" type="o:undefinedENUM"/>
                <xs:attribute name="inheritAllowed" type="xs:boolean"/>
                <xs:attribute name="inheritFrom" type="o:URIQnameQcode"/>
                <xs:attribute name="inheritRelation" type="o:URIQnameQcode"/>
                <xs:anyAttribute namespace="##other" processContents="lax"/>     
    </xs:complexType>
    
    <xs:element name="permission" type="o:permCT"/>
    <xs:complexType name="permCT">
           <xs:sequence>
                    <xs:element ref="o:asset" maxOccurs="unbounded"/>
                    <xs:element ref="o:action" />
                    <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:sequence>
           <xs:attributeGroup ref="o:idAttributes"/>        
    </xs:complexType>
    
    <xs:element name="prohibition" type="o:prohibCT"/> 
    <xs:complexType name="prohibCT">
        <xs:sequence>
            <xs:element ref="o:asset"  maxOccurs="unbounded"/>
            <xs:element ref="o:action" />
            <xs:element ref="o:constraint" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element ref="o:party"  minOccurs="0" maxOccurs="unbounded"/>
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>
    
    <xs:element name="duty" type="o:dutyCT"/>
    <xs:complexType name="dutyCT">
        <xs:sequence>
            <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:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="uid" type="o:URIQnameQcode"/>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>
    
    <xs:element name="asset" type="o:assetCT"/> 
    <xs:complexType name="assetCT">
        <xs:attribute name="uid" type="o:URIQnameQcode" /> <!--Required Attribute-->
        <xs:attribute name="relation" type="o:URIQnameQcode" /> <!--Required Attribute-->
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>
    
    <xs:element name="party" type="o:partyCT"/>
    <xs:complexType name="partyCT">
        <xs:attribute name="uid" type="o:URIQnameQcode"/> <!--Required Attribute-->
        <xs:attribute name="function" type="o:URIQnameQcode" /> <!--Required Attribute-->
        <xs:attribute name="scope" type="o:URIQnameQcode"/>
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>
 
    <xs:element name="action" type="o:actionCT"/>
    <xs:complexType name="actionCT">
        <xs:attribute name="name" type="o:URIQnameQcode" /> <!--Required Attribute-->
        <xs:attributeGroup ref="o:idAttributes"/>
    </xs:complexType>
    
    <xs:element name="constraint" type="o:constraintCT"/>
    <xs:complexType name="constraintCT">
        <xs:attribute name="name" type="o:URIQnameQcode" /> <!--Required Attribute-->
        <xs:attribute name="operator" type="o:URIQnameQcode" /> <!--Required Attribute-->
        <xs:attribute name="rightOperand" type="o:listOfValues" /> <!--Required Attribute-->
        <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="conflictENUM">
        <xs:restriction base="xs:string">
            <xs:enumeration value="perm"/>
            <xs:enumeration value="prohibit"/>
            <xs:enumeration value="invalid"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="undefinedENUM">
        <xs:restriction base="xs:string">
            <xs:enumeration value="support"/>
            <xs:enumeration value="ignore"/>
            <xs:enumeration value="invalid"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="URIQnameQcode">
        <xs:union memberTypes="xs:anyURI xs:QName o:QCode"/>
    </xs:simpleType>
    
    <xs:simpleType name="QCode">
        <xs:restriction base="xs:string">
            <xs:pattern value="[^\s:]+:[^\s]+"/>
        </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>
