<?xml version="1.0"?>

<!-- JSDAI Query syntax specification Version 1.2                  -->
<!-- --------------------------------------------                  -->
<!-- Copyright (c) 2003 LKSoftWare GmbH                            -->
<!-- $Id$ -->

<!-- *************** Query ***************                         -->
<!--                    query                                      -->
<!--                    The top element of a query document        -->
<!ELEMENT  query        (domain | result | query-lib)+               >

<!--         xmlns      Namespace specification
             context    Execution context (local or remote)
             scope      The scope of the query. The default is
                        "transaction". The scope specifies query
                        life span. Some implementations ignore
                        the scope.
             xmlns:pfx  Sample query element namespace
             query-element-prefixes
                        The prefixes that should be treated as part
                        of query. In example DTD this is "pfx".    -->
<!ATTLIST  query
             xmlns      CDATA
                        #FIXED "http://www.lksoft.com/SDAI/Query/V1.1" 
             xmlns:pfx  CDATA                              #IMPLIED
             context    (local|remote)                   "local"
             scope      (transaction|session|global)       #IMPLIED
             query-element-prefixes
                        NMTOKENS                           #REQUIRED >

<!-- *************** Query Library ***************                 -->
<!--                    query                                      -->
<!--                    The top element of query library or child
                        of query as local query library             -->
<!ELEMENT  query-lib    (query-ent)+                                 >
<!--         id         Query library identifier which can be used by
                        another query as part of query-lib URI.
             idref      Query library reference identifier used to
                        reference query defined before when attribute
                        remove is used.
             scope      The scope of the query library. The default
                        is "transaction". If query-lib is a child of
                        query then scope can not be specified
                        explicitly and "local" scope is assumed.
             remove     The remove operation on a previously defined
                        query library.
             ** The following attributes are only used **
             ** when query-lib is a top element        **
             xmlns      Namespace specification
             context    Execution context (local or remote)
             xmlns:pfx  Sample query element namespace
             query-element-prefixes
                        The prefixes that should be treated as part
                        of query. In example DTD this is "pfx".    -->
<!ATTLIST  query-lib
             id         NMTOKEN                            #IMPLIED
             idref      NMTOKEN                            #IMPLIED
             scope      (transaction|session|global)       #IMPLIED
             remove     (yes)                              #IMPLIED
             xmlns      CDATA
                        #FIXED "http://www.lksoft.com/SDAI/Query/V1.1"
             xmlns:pfx  CDATA                              #IMPLIED
             context    (local|remote)                   "local"
             query-element-prefixes
                        NMTOKENS                           #IMPLIED  >

<!-- *************** Domain ***************                        -->
<!-- Since domain is not supported this part of DTD is outdated    -->
<!--                    domain                                     -->
<!--                    Query domain on which query is
                        performed                                  -->
<!ELEMENT  domain       (repository | model | schema-instance)+      >

<!--                    repository                                 -->
<!--                    Repository where to query                  -->
<!ELEMENT  repository   (name | description | change-date | author |
                         organization | preprocessor-version |
                         originating-system | authorization |
                         default-language | context-identifiers)*    >

<!--                    model                                      -->
<!--                    Model where to query                       -->
<!ELEMENT  model        (name | underlying-schema | change-date |
                         default-language | context-identifiers)*    >

<!--                    schema-instance                            -->
<!--                    Schema instance where to query             -->
<!ELEMENT  schema-instance
                        (name | native-schema | change-date |
                         validation-date | validation-result |
                         validation-level | description | author |
                         organization | preprocessor-version |
                         originating-system | authorization |
                         default-language | context-identifiers)*    >

<!--                    name                                       -->
<!--                    Name of repository, model, or schema
                        instance                                   -->
<!ELEMENT  name         (#PCDATA)                                    >

<!--                    description                                -->
<!--                    Description of repository or schema
                        instance                                   -->
<!ELEMENT  description  (#PCDATA)                                    >

<!--                    change-date                                -->
<!--                    Date of recent modification of
                        repository, model, or schema
                        instance. String in ISO format             -->
<!ELEMENT  change-date  (#PCDATA)                                    >

<!--                    author                                     -->
<!--                    Author of repository or schema instance    -->
<!ELEMENT  author       (#PCDATA)                                    >

<!--                    organization                               -->
<!--                    Organization of repository or schema
                        instance                                   -->
<!ELEMENT  organization (#PCDATA)                                    >

<!--                    preprocessor-version                       -->
<!--                    Preprocessor version of repository or
                        schema instance                            -->
<!ELEMENT  preprocessor-version
                        (#PCDATA)                                    >

<!--                    originating-system                         -->
<!--                    Originating system of repository or
                        schema instance                            -->
<!ELEMENT  originating-system
                        (#PCDATA)                                    >

<!--                    authorization                              -->
<!--                    Authorization of repository or schema
                        instance                                   -->
<!ELEMENT  authorization
                        (#PCDATA)                                    >


<!--                    default-language                           -->
<!--                    Default language of repository, model, or
                        schema instance                            -->
<!ELEMENT  default-language
                        (#PCDATA)                                    >

<!--                    context-identifiers                        -->
<!--                    Context identifiers of repository, model,
                        or schema instance                         -->
<!ELEMENT  context-identifiers
                        (#PCDATA)                                    >

<!--                    underlying-schema                          -->
<!--                    Underlying schema of the model             -->
<!ELEMENT  underlying-schema
                        (#PCDATA)                                    >

<!--                    native-schema                              -->
<!--                    Native schema of the schema instance       -->
<!ELEMENT  native-schema
                        (#PCDATA)                                    >

<!--                    validation-date                            -->
<!--                    Validation date of the schema
                        instance. String in ISO format             -->
<!ELEMENT  validation-date
                        (#PCDATA)                                    >

<!--                    validation-result                          -->
<!--                    Validation result of the schema
                        instance. An integer                       -->
<!ELEMENT  validation-result
                        (#PCDATA)                                    >

<!--                    validation-level                           -->
<!--                    Validation level of the schema
                        instance. An integer                       -->
<!ELEMENT  validation-level
                        (#PCDATA)                                    >

<!-- *************** End domain ***************                    -->

<!-- *************** Constraint entities ***************           -->
<!--                    set-operations                             -->
<!--                    List of all set operations                 -->
<!ENTITY % set-operations
                       "intersect | union | and | or | not"          >

<!--                    comparison-operations                      -->
<!--                    List of all comparison operations          -->
<!ENTITY % comparison-operations
                       "eq | neq | regex | nregex"                   >

<!--                    constraints-list                           -->
<!--                    List of common constraints                 -->
<!ENTITY % constraint-list
       "pfx:type | pfx:fwd | pfx:inv | pfx:val | %set-operations;"   >

<!--                    constraints                                -->
<!--                    Constraint list                            -->
<!-- Output: input instance subset that match child constraints    -->
<!ENTITY % constraints "(%constraint-list;)*"                        >

<!--                    Constraints or several compound constraint
                        groups                                     -->
<!ENTITY % constraints-or-group
                       "((%constraint-list; |
                        %comparison-operations;)+ | (grp)+)"         >

<!--                    Yes or no answer                           -->
<!--                    Defines values of boolean type attributes  -->
<!ENTITY % yes-no      "(yes | no | true | false)"                   >

<!--                    Entity name                                -->
<!ENTITY % ent         "ent NMTOKEN"                                 >

<!--                    Attribute name                             -->
<!ENTITY % attr        "attr NMTOKEN"                                >

<!--                    Aggregate member(s)                        -->
<!--                    Possible values: * or integer index        -->
<!ENTITY % aggr        "aggr CDATA"                                  >

<!-- *************** End constraint entities ***************       -->

<!--                    Aggregate size                             -->
<!--                    Value: an integer                          -->
<!ENTITY % aggr-size   "aggr-size CDATA"                             >

<!-- *************** Query library elements ***************        -->
<!--                    query-ent                                  -->
<!--                    Query library entity definition            -->
<!ELEMENT  query-ent    (query-type, (query-fwd | query-val)* )       >
<!--         name       Name of the entity                         -->
<!ATTLIST  query-ent
             name       NMTOKEN                            #REQUIRED >

<!--                    query-type                                 -->
<!--                    Query library type constraint definition   -->
<!ELEMENT  query-type   %constraints;                                >

<!--                    query-fwd                                  -->
<!--                    Query library fwd constraint definition    -->
<!ELEMENT  query-fwd    %constraints;                                >
<!--         %attr;     Attribute name
             target     Type of the target entity instance         -->
<!ATTLIST  query-fwd
            %attr;                                         #REQUIRED
             target     NMTOKEN                            #IMPLIED  >

<!--                    query-val                                  -->
<!--                    Query library val constraint definition    -->
<!ELEMENT  query-val    %constraints;                                >
<!--         %attr;     Attribute name
             select     Optional select path                       -->
<!ATTLIST  query-val
            %attr;                                         #REQUIRED
             select     NMTOKENS                           #IMPLIED  >

<!-- *************** End query library elements ***************    -->

<!-- *************** Constraints ***************                   -->
<!-- Query result definition                                       -->
<!--                    result                                     -->
<!--                    Query result definition                    -->
<!ELEMENT  result       %constraints;                                >
<!--         name       Name of the named query result
             distinct   Return distinct results (default is no)
             entity-type-index
                        Return optional entity type index for entity
                        instances                                  -->
<!ATTLIST  result
             name       NMTOKEN                            #IMPLIED
             distinct   %yes-no;                           #IMPLIED
             entity-type-index
                        %yes-no;                           #IMPLIED  >

<!--                    pfx:type                                   -->
<!--                    (Sub)Type of entity constraint             -->
<!-- Output: input instance subset that match the specified type   -->
<!-- Child constraints can further restrict the output set.        -->
<!-- See: ENTITY % constraints                                     -->
<!ELEMENT  pfx:type     %constraints;                                >
<!--         ent        Entity type
             exact      If this is an exact (sub)type              -->
<!ATTLIST  pfx:type
             %ent;                                         #REQUIRED
             exact      %yes-no;                           #IMPLIED  >

<!--                    pfx:fwd                                    -->
<!--                    Forward reference (attribute value)        -->
<!-- Output: a set of instances that are attribute values of       -->
<!--         the input instance set                                -->
<!-- Child constraints can further restrict the output set.        -->
<!-- See: ENTITY % constraints                                     -->
<!ELEMENT  pfx:fwd      %constraints;                                >
<!--         %ent;      Entity to which attribute belongs
             %attr;     Attribute of the reference
             %aggr;     Aggregate memeber(s)
             %aggr-size;Aggregate size(s). Only one of aggr or
                        aggr-size can be specified.
             target     Type of the target entity instance         -->
<!ATTLIST  pfx:fwd
            %ent;                                          #IMPLIED
            %attr;                                         #REQUIRED
            %aggr;                                         #IMPLIED
            %aggr-size;                                    #IMPLIED
             target     NMTOKEN                            #IMPLIED  >

<!--                    pfx:inv                                    -->
<!--                    Inverse reference                          -->
<!-- Output: a set of instances that reference (are users of)      -->
<!--         the input instance set                                -->
<!-- Child constraints can further restrict the output set.        -->
<!-- See: ENTITY % constraints                                     -->
<!ELEMENT  pfx:inv      %constraints;                                >
<!--         %attr;     Attribute pointing to current entities
             %ent;      Entity to which attribute belongs
             %aggr;     Aggregate member(s)
             %aggr-size;Aggregate size(s). Only one of aggr or
                        aggr-size can be specified.                -->
<!ATTLIST  pfx:inv
            %attr;                                         #REQUIRED
            %ent;                                          #REQUIRED
            %aggr;                                         #IMPLIED
            %aggr-size;                                    #IMPLIED  >

<!--                    pfx:val                                    -->
<!--                    Value of the attribute which is not of
                        instance type. Use fwd for attributes that
                        are entity instances.                      -->
<!-- Output: input instance subset that matches specified value    -->
<!--         constraints or is set if child constraints are        -->
<!--         not specified                                         -->
<!ELEMENT  pfx:val      (%comparison-operations; | and | or)?        >
<!-- Only %comparison-operations; can be used inside and/or but    -->
<!-- DTD is not restrictive enough                                 -->
<!--         %ent;      Entity to which attribute belongs
             %attr;     Attribute of the reference
             select     Select path
             %aggr;     Aggregate member(s)
             %aggr-size;Aggregate size(s). Only one of aggr or
                        aggr-size can be specified.
             sort       Sets sorting of the result on this value.
                        This optional attribute can by set only
                        inside <items>. Value asc denotes
                        ascending sort and value desc denotes
                        descending sort. Currently this attribute
                        is supported only by jsdai:database:
                        remote queries    -->
<!ATTLIST  pfx:val
            %ent;                                          #IMPLIED
            %attr;                                         #REQUIRED
             select     NMTOKENS                           #IMPLIED
            %aggr;                                         #IMPLIED
            %aggr-size;                                    #IMPLIED
             sort       (asc|desc)                         #IMPLIED  >

<!--                    intersect                                  -->
<!--                    Intersects resulting entity sets           -->
<!-- Output: intersection of output instance sets that are         -->
<!--         received at the end of each child constraint path     -->
<!ELEMENT  intersect    %constraints-or-group;                       >

<!--                    union                                      -->
<!--                    Unites resulting entity sets               -->
<!-- Output: union of output instance sets that are                -->
<!--         received at the end of each child constraint path     -->
<!ELEMENT  union        %constraints-or-group;                       >

<!--                    and                                        -->
<!--                    And operation on input instances           -->
<!-- Output: input instance subset that matches all                -->
<!--         child constraints                                     -->
<!ELEMENT  and          %constraints-or-group;                       >

<!--                    or                                         -->
<!--                    Or operation on input instances            -->
<!-- Output: input instance subset that matches at least one       -->
<!--         child constraint                                      -->
<!ELEMENT  or           %constraints-or-group;                       >

<!--                    not                                        -->
<!--                    Instances that don't match constrain.      -->
<!-- Output: input instance subset that does not match             -->
<!--         child constraint                                      -->
<!ELEMENT  not          %constraints;                                >
<!-- *************** End constraints ***************               -->

<!-- *************** value comparison ***************              -->
<!-- Comparison operators can be combined using and/or             -->
<!--                    eq                                         -->
<!--                    Equal match.                               -->
<!--         param      Optional name of parameter to bind
                        expected value to. If this attribute is
                        specified then nested #PCDATA should not
                        be used.                                   -->

<!ELEMENT  eq           (#PCDATA)                                    >
<!ATTLIST  eq
             param      NMTOKEN                            #IMPLIED  >

<!--                    neq                                        -->
<!--                    Not equal match.                           -->
<!--         param      Optional name of parameter to bind
                        expected value to. If this attribute is
                        specified then nested #PCDATA should not
                        be used.                                   -->
<!ELEMENT  neq          (#PCDATA)                                    >
<!ATTLIST  neq
             param      NMTOKEN                            #IMPLIED  >

<!--                    regex                                      -->
<!--                    Regular expression match.                  -->
<!--         param      Optional name of parameter to bind
                        expected value to. If this attribute is
                        specified then nested #PCDATA should not
                        be used.                                   -->
<!ELEMENT  regex        (#PCDATA)                                    >
<!ATTLIST  regex
             param      NMTOKEN                            #IMPLIED  >

<!--                    nregex                                     -->
<!--                    Regular expression negative match.         -->
<!--         param      Optional name of parameter to bind
                        expected value to. If this attribute is
                        specified then nested #PCDATA should not
                        be used.                                   -->
<!ELEMENT  nregex       (#PCDATA)                                    >
<!ATTLIST  nregex
             param      NMTOKEN                            #IMPLIED  >

<!-- *************** End value comparison ***************          -->

<!--                    grp                                        -->
<!--                    Group of several constraints as one
                        compound constraint                        -->
<!ELEMENT  grp          %constraints;                                >

<!--                    items                                      -->
<!--                    Defines result set items. Can be used only
                        as direct last element of <result>         -->
<!-- Output: input instances (if instances is "include") and child -->
<!-- constraint instances and/or values                            -->
<!ELEMENT  items        %constraints-or-group;                       >
<!--         instances  Specifies if the input instance set has to be
                        included in the result set.                -->
<!ATTLIST  items
             instances  (include|exclude)                  "include" >

<!-- *************** End query ***************                     -->

<!-- Change history: 
     $Log$
     Revision 1.5  2006/06/29 16:17:11  vaidas
     Added scope attribute to query element.

     Revision 1.4  2006/05/19 17:14:01  vaidas
     Added documentation for param attributes and extended val with sort attribute.

     Revision 1.3  2006/05/18 11:12:07  vaidas
     Upgraded to spec version 1.2 with parameter support. This version is implemented by JSDAI 4.1.0

     Revision 1.2  2003/12/23 10:16:33  vaidas
     Updates for version 3.6.0

     Revision 1.1  2003/07/03 16:52:50  vaidas
     Specification upgraded to version 1.1

     Revision 1.4  2003/01/24 10:49:12  vaidas
     Fixed typo in comments.

     Revision 1.3  2002/12/12 16:39:45  vaidas
     First real specification.
     Updates from query implementation prototype.
     Comments describing how constraints work added.

     Revision 1.2  2002/12/12 16:32:12  vaidas
     First incomplete draft dated 2002-11-21
-->
