XSD限制多个元素的值

时间:2016-06-20 07:48:00

标签: xml xsd xsd-validation

我的数据源包含productindextype的有效组合。 说有效组合是

  1. 产品 - ProductFoo
  2. index - indexA
  3. type - typeA
    1. 产品 - ProductBar
    2. index - indexB
    3. type - typeB
    4. 以下是有效的XML

      <Entity name = "foo">
              <product>ProductFoo</product>
              <index>indexA</index>
              <type>typeA</type>
      </Entity>
      

      而以下不是:

      <Entity name = "bar">
              <product>ProductBar</product>
              <index>indexA</index>
              <type>typeA</type>
      </Entity>
      

      我尝试过使用选择,枚举但可能没有正确使用它。如果可以使用XSD完成任何想法?

1 个答案:

答案 0 :(得分:0)

XSD 1.1的条件类型分配允许您根据Entity属性改变@name的类型,而XSD 1.1的断言可以让您约束product

的内容

但是,如果可能,请考虑更改XML设计:

<foo>
  <ProductFoo/>
  <indexA/>
  <typeA/>
</foo>

然后您的XML将能够简单地在XSD 1.0中建模。