基于其他属性值的属性的条件存在

Conditional presence of attributes based on other attribute values

我有一个 XML 需要使用模式进行非常严格的验证。 问题是某些元素的某些属性仅在 "type" 属性具有特定值时才需要。

例如:

<someElement type="foo" att1="bla" />
<someElement type="bar" att1="blu" />

在我的例子中,对于 type="foo" 应该可以正常验证,但是对于 type="bar" 它不应该,因为对于 "bar" 另一个属性 att2 必须存在。

这种事情甚至可以使用模式,还是我需要声明一个新的 complexType 而不是 <someElement> 只允许我需要的东西?

我尝试了 "similar questions" 部分,但找不到专门解决此问题的内容。

您所描述的与 XSD 1.1 中的 "conditional type assignment" 机制几乎完全匹配(其中一个属性的值用于决定验证几种类型中的哪一种) .

在 XSD 1.0 中无法做到这一点。