I have an XML like this (a workflow represents a sort of a class that is instantiated by a process).
<workflowManagementSystem>
<workflows>
<workflow name="workflow1">
<actions>
<action name="action1" role="role1"></action>
<action name="action2" role="role3"></action>
<action name="action3" role="role4"></action>
</actions>
</workflow>
<workflow name="workflow2">
<actions>
<action name="action3" role="role4"></action>
<action name="action2" role="role3"></action>
<action name="action4" role="role4"></action>
</actions>
</workflow>
</workflows>
<actors>
<actor name="actor1" role="role1"></actor>
<actor name="actor2" role="role2"></actor>
<actor name="actor3" role="role3"></actor>
<actor name="actor4" role="role4"></actor>
<actor name="actor5" role="role2"></actor>
</actors>
<processes>
<process workflow="workflow1">
<actionStatuses>
<actionStatus action="action1" actor="actor1"></actionStatus>
<actionStatus action="action2" actor="actor3"></actionStatus>
</actionStatuses>
</process>
<process workflow="workflow1">
<actionStatuses>
<actionStatus action="action1" actor="actor1"></actionStatus>
<actionStatus action="action2" actor="actor5"></actionStatus>
<actionStatus action="action3" actor="actor4"></actionStatus>
</actionStatuses>
</process>
<process workflow="workflow1">
<actionStatuses>
<actionStatus action="action2" actor="actor5"></actionStatus>
<actionStatus action="action4" actor="actor4"></actionStatus>
</actionStatuses>
</process>
</processes>
</workflowManagementSystem>
I’d like to declare some constraints like:
1) The name of the workflow has to be unique.
2) The name of the action has to be unique within the scope of the workflow containing it.
3) An action can be repeated within the process (more actionStatus referring to the same action).
4) An actionStatus should refer only to the action belonging to the particular workflow instantiated by the father process.
5) The actor indicated in actionStatus must belong to the same role as specified in the action to which it refers.
Is it possible?
Some or your requirements can, others cannot be done using XML Schema.
One note before going into details, I’ve also added an additional key/keyref (referential integrity), that you did not ask for, but I thought it might be good for future references. The uniqueWorkflowInWorkflows is what you’ve asked for; the pkWorkflow/fkProcessToWorkflow I’ve added. There are subtle differences between unique and key clauses, but if you accept the key/keyref, you don’t need uniqueWorkflowInWorkflows.
It is worth mentioning here that in general, if your design allows for an xsd:unique clause, but not an xsd:key; an xsd:keyref can reference an xsd:unique…
The answers are:
1) See uniqueWorkflowInWorkflows or pkWorkflow
2) See uniqueActionInWorkflow
3) Nothing to do here.
4) Cannot be done in XML Schema (intuitively I would say due to limitations in the supported XPath syntax for the selectors).
5) Cannot be done in XML Schema.
Below is an XML Schema generated from your XML, following a Russian Doll authoring style, that is the only “global” declaration is that of the root element.
This is a visualization of the XSD source: