Home MORPH Syntax Keys
  Sponsored by Magnetar Games Main Specification Forum Syntax

MORPH Syntax

Keys

To aid in validation, XML Schema xs:key elements may be declared for user attributes. Such keys are not required for the model to be complete.

The specific keys that a DSL requires depends on the DSL. Generally, anywhere that one place of the instance document references a name declared elsewhere in that same instance document, a key should be used. In particular, the "Ref" attribute of all UserAttribute elements should be keyed to the Prototype or ObjectClasses object name. Also the "Prototype" attribute of the Instance element should be keyed to the Prototype declaration.

Creating Keys

The basic syntax for creating a key is shown below. Please see XML Schema resources for more details on the syntax.

To create a key, first one must mark the unique identifier which will be used for the key. This is done with the xs:key element as shown below.

<xs:key name="(ClassName)ClassKey">

<xs:selector xpath="Prototypes/(ClassSet)/(Class)"/>
<xs:field xpath="@Name"/>
</xs:key>

This example would mark the "Name" attribute of "Class" which is under "ClassSet" under "Prototypes" as the key. The DSL must change the "Class" and "ClassSet" placeholders as necessary to reflect the correct level of nesting and the correct early-bound element names.

Once defined, the same key may be referenced multiple times. To set up a key reference, or a tie back to the key defined previously, the following syntax is used.

<xs:keyref name="(ClassName)ClassKeyInstanceRef" refer="(ClassName)ClassKey">

<xs:selector xpath="Instances/(Class)/(ClassSet)/Instance"/>
<xs:field xpath="@Prototype"/>
</xs:keyref>

Note that the "refer" attribute references the key as defined above.

Here is another example, using the same key but a different reference.

<xs:keyref name="(ClassName)ClassKeyHierRef" refer="(ClassName)ClassKey">

<xs:selector xpath="Hierarchies/(ClassSet)/(Class)"/>
<xs:field xpath="@Ref"/>
</xs:keyref>

Using this same method, many keys may be built to cross-reference various parts of the DSL.