+ ((string= name "occurrence")
+ (attributes node '("reifier") nil)
+ (when (attr node "reifier")
+ (resolve-iri (attr node "reifier") *document-iri* node))
+ (let ((phase 0) (type-seen nil) (scope-seen nil) (resource-seen nil))
+ (dolist (child (elements node))
+ (check-namespace child)
+ (let* ((kind (node-name child))
+ (next (cond ((string= kind "itemIdentity") 0)
+ ((string= kind "type") 1)
+ ((string= kind "scope") 2)
+ ((member kind '("resourceData" "resourceRef") :test #'string=) 3))))
+ (unless next (reject :unexpected-element (format nil "Unexpected ~A element." kind) child))
+ (when (< next phase) (reject :element-order "occurrence child order is invalid." child))
+ (setf phase next)
+ (cond
+ ((string= kind "itemIdentity") nil)
+ ((string= kind "type")
+ (when type-seen (reject :duplicate-occurrence-type "Only one occurrence type is allowed." child))
+ (setf type-seen t))
+ ((string= kind "scope")
+ (unless type-seen (reject :missing-occurrence-type "occurrence requires type before scope." child))
+ (when scope-seen (reject :duplicate-occurrence-scope "Only one occurrence scope is allowed." child))
+ (setf scope-seen t))
+ (t
+ (unless type-seen (reject :missing-occurrence-type "occurrence requires type before its resource." child))
+ (when resource-seen (reject :occurrence-resource-cardinality "occurrence requires exactly one resource." child))
+ (setf resource-seen t)))
+ (validate child '("itemIdentity" "type" "scope" "resourceData" "resourceRef"))))
+ (unless type-seen (reject :missing-occurrence-type "occurrence requires a type element." node))
+ (unless resource-seen (reject :missing-occurrence-resource "occurrence requires a resource element." node))))
+ ((member name '("association" "role") :test #'string=)
+ (attributes node '("reifier") nil)
+ (when (attr node "reifier")
+ (resolve-iri (attr node "reifier") *document-iri* node))
+ (let ((association-p (string= name "association"))
+ (phase 0) (type-seen nil) (scope-seen nil) (participants 0))
+ (dolist (child (elements node))
+ (check-namespace child)
+ (let* ((kind (node-name child))
+ (next (cond ((string= kind "itemIdentity") 0)
+ ((string= kind "type") 1)
+ ((and association-p (string= kind "scope")) 2)
+ ((string= kind (if association-p "role" "topicRef")) 3))))
+ (unless next (reject :unexpected-element (format nil "Unexpected ~A element." kind) child))
+ (when (< next phase) (reject :element-order (format nil "~A child order is invalid." name) child))
+ (setf phase next)
+ (cond
+ ((string= kind "itemIdentity") nil)
+ ((string= kind "type")
+ (when type-seen (reject :duplicate-type (format nil "Only one ~A type is allowed." name) child))
+ (setf type-seen t))
+ (t
+ (unless type-seen
+ (reject :missing-type (format nil "~A requires type before ~A." name kind) child))
+ (if (string= kind "scope")
+ (progn
+ (when scope-seen (reject :duplicate-scope "Only one association scope is allowed." child))
+ (setf scope-seen t))
+ (progn
+ (incf participants)
+ (when (and (not association-p) (> participants 1))
+ (reject :role-player-cardinality "role requires exactly one topicRef player." child))))))
+ (validate child (if association-p '("itemIdentity" "type" "scope" "role") '("itemIdentity" "type" "topicRef")))))
+ (unless type-seen (reject :missing-type (format nil "~A requires a type element." name) node))
+ (when (zerop participants)
+ (reject (if association-p :missing-roles :missing-role-player)
+ (if association-p "association requires at least one role." "role requires a topicRef player.") node))))