如何在XSD中定义常量

Ste*_*bbi 5 xsd constants

有没有一种方法可以定义一个常量值,并在之前的XSD中使用该常量?我有一个通用值,想用于各种xs:element标签的maxOccurs属性。像其他语言中的常量一样,如果要更改支持MyConst的值,我想在一处进行更改。

<!-- Can I do this? -->
<ConstantValue id="MyConst" value="10"/>
...
<xs:element name="sandwich_meat" type="xs:string" minOccurs="0" maxOccurs="MyConst"/>
<xs:element name="sandwich_name" type="xs:string" minOccurs="0" maxOccurs="MyConst"/>
Run Code Online (Sandbox Code Playgroud)

小智 2

不,这样是不允许的。但是,您可以在 XSD 顶部的某个位置使用固定值定义自己的类型(放置很重要),并将该类型用于元素。