【发布时间】:2020-05-22 16:50:54
【问题描述】:
给定一个定义了某种类型元素的模式,是否可以允许该类型被扩展,但该扩展元素仍然是强类型的?换句话说,添加某种可以从外部架构中使用的扩展点来添加只能在该位置使用的元素?
假设架构看起来有点像:
<xs:schema …>
<xs:element name="Match" type="tns:TNodeConstraint" />
<xs:complexType name="TNodeConstraint">
<xs:group ref="tns:Expression" />
</xs:complexType>
<xs:group name="Expression">
<xs:choice>
<xs:element name="And">
<xs:complexType … />
</xs:element>
<xs:element name="Or">
<xs:complexType … />
</xs:element>
<xs:element name="IsAbstract">
<xs:element name="IsExtern">
<!-- Some kind of extension point? -->
</xs:choice>
</xs:group>
</xs>
是否可以扩展Expression 组,以便第二个外部架构可以说我可以在这里接受IsMyCustomConstraint,但不能接受IsMyCustomSortOrder?所以这将是有效的:
<Match>
<IsAbstract />
<IsExtern />
<IsMyCustomConstraint />
</Match>
但这会无效吗?
<Match>
<IsAbstract />
<IsExtern />
<IsMyCustomSortOrder />
</Match>
- 我不想使用
xs:any,因为这会允许在约束可以去的地方放置“排序顺序”。 - 我可以修改原始架构
- 我可以控制
IsMyCustomConstraint和IsMyCustomSortOrder的命名空间,它们是否匹配原始架构并不重要。
【问题讨论】:
标签: xsd