Entity and Attribute Definitions

Entities in the Datastore are defined as elements with complexType definitions. Each entity's definition must appear at global level in the schema. If an entity incorporates another entity as part of its definition, the incorporated entity must still be defined at global level and referred to by the incorporating entity.

In the example below, the Application entity incorporates the Person entity, which in turn incorporates the Address entity. All three entities are defined at global level and use element ref to refer to the definitions of other entities.

<xs:element name="Application">
        <xs:complexType>
            <xs:sequence minOccurs="0">
                <xs:element ref="Person" minOccurs="0" 
                maxOccurs="unbounded" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="Person">
        <xs:complexType>
            <xs:sequence minOccurs="0">
                <xs:element ref="Address" 
                minOccurs="0" 
                maxOccurs="1" />
                ...
            </xs:sequence>
            <xs:attribute name="firstName" type="D:SVR_STRING" />
            ...
        </xs:complexType>
    </xs:element>

    <xs:element name="Address">
        ...
    </xs:element>

There are other restrictions on entities. All complex type compositors must be sequences, that is, you may use the "sequence" compositor but not "all" or "choice". All sequences must have a "minOccurs" of zero, and all elements must have a "minOccurs" of zero. There is no restriction on the value of the "maxOccurs" constraint.

Attributes of entities must be of "domain" types, that is, they must be simpleType definitions defined elsewhere in the schema. An attribute can have a default value, which (unlike the "default" annotation on domains) does directly affect the values that get stored on the Datastore if the attribute value is not explicitly set.

The datastore definition will usually consist of many simpleType (domain) and complexType (entity) definitions. All of these must appear at global level, that is, they cannot be nested inside each other.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:D="http://www.curamsoftware.com/BaseDomains"
>
    
    <xs:import 
    namespace="http://www.curamsoftware.com/BaseDomains" />
    
    <xs:simpleType name="DECEASED_IND">
        <xs:restriction base="D:SVR_BOOLEAN"/>
    </xs:simpleType>
    
    <xs:element name="Person">
        <xs:complexType>
            <xs:attribute name="firstName" type="D:SVR_STRING" />
            <xs:attribute name="middleInitial" 
            type="D:SVR_STRING" />
            <xs:attribute name="lastName" type="D:SVR_STRING" />
            <xs:attribute name="deceased" type="DECEASED_IND" />
        </xs:complexType>
    </xs:element>
    
</xs:schema>