From RFC 7950#7.9.4:
The behavior of the [mandatory] constraint depends on the type of the choice's closest ancestor node in the schema tree that is not a non-presence(see Section 7.5.1):
- If no such ancestor exists in the schema tree, the constraint is enforced.
- Otherwise, if this ancestor is a case node, the constraint is enforced if any other node from the case exists.
- Otherwise, it is enforced if the ancestor node exists.
Now: the first and the last point seems to be quite straightforward, but I can't get the second one.
Is it trying to say that if first non-presence container
ancestror is a case
node, then the constraint must be enforced if the case
has more than one child? Basically, it means that I must enforce the mandatory if the case
contains a uses
?
A mandatory choice means that exactly one case branch (case's data node descendants) MUST exist in a valid instance document - the RFC refers to this with the term "valid data". The second bullet is an exception.
The second bullet applies to nested choices - if a choice's ancestor is a case node you are dealing with a choice nested within another choice.
In the above example the mandatory choice constraint is not enforced, until leaf
f
is also present in the instance document. If leaf nodes from eithera-b-c
ord-e
branch are instantiated, the constraint will also be enforced, but the condition will always be satisfied.No. The constraint is enforced if there are instances of such children in the instance document.
Mandatory constraints apply to instance documents, not the schema - the schema only dictates the constraints. A
uses
will never exist in a context where mandatory constraints are enforced. Only instantiated data nodes defined by the referenced grouping may exist in such a context and may be considered when enforcing the constraint.