简体   繁体   中英

How to specify Constraints in XSD (XML Schema Definition)?

Problem

I want to modell the following in XSD (XML Schema definition).

I have the following relationship between three classes:

在此输入图像描述

Textuell description:

  • Each Widget references 0 or more Actions
  • Each Trigger references one Widget and one Action
  • Widgets may be referenced by 0 or more Triggers
  • Actions may be referenced by 0 ore more Widgets and 0 or more Triggers
  • The Action referenced by a Trigger must also be referenced by "the Triggers Widget " (and thats the problem)

In my XSD each class is modelled as a complexType .

Question

Is it possible to to model the constraint (orange note, last point) in XSD ? If yes, how? In UML I'd use a Composite Structure Diagram or OCL .

I believe this is referred to as a co-constraint: you want to put a rule into Trigger 's definition that impacts the content of two other things at the same time: something in Widget must contain something from Action .

You can't do that with XSD, but you can do it with Schematron . Schematron will let you write a rule with an XPath expression that checks a contains relationship . That Xpath expression would then be your rule that you'd check against.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM