<xs:all> 下的元素重复 [英] Element repetition under &lt;xs:all&gt;

查看:44
本文介绍了<xs:all> 下的元素重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据结构是这样的

<datastructure>
  <field1>data</field1>
  <field2>data</field2>
  <field3>data</field3>
  <field4>data</field4>
  <field4>data</field4>
  <field4>data</field4>
  <field4>data</field4>
</datastructure>

所有字段都必须恰好出现一次,除了 field4 可以出现 [0, unbounded] 次.也没有充分的理由关心订单.

All fields must appear exactly one time, except field4 which can appear [0, unbounded] times. Also there's no good reason to care about the order.

我无法提供模式来验证这一点.使用序列将作为:

I could not come with a schema to validate this. Using sequence will work as:

<xs:element name="datastructure" type="datastructureType"/>
<xs:complexType name ="datastructureType">
  <xs:sequence>
    <xs:element name="field1"/>
    <xs:element name="field2" />
    <xs:element name="field3"/>
    <xs:element name="field4" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>

但这强加了一个我没有充分理由强加的命令.另一种方法是使用 all,但这需要将 xml 修改为:

But that imposes an order which I have no good reason for imposing. The alternative is using all, but that requires modifying the xml to:

<datastructure>
  <field1>data</field1>
  <field2>data</field2>
  <field3>data</field3>
  <field4List>
    <field4>data</field4>
    <field4>data</field4>
    <field4>data</field4>
    <field4>data</field4>
  </field4List>
</datastructure>

因为所有的孩子最多只能有一个 maxOccurs.这增加了 field4List 的负担,它在所有实际方面似乎都没用.

Because the children of all can only have maxOccurs up to one. This adds the burden of field4List, which seems to be useless in all practical regards.

如何编写一个模式来验证我的 xml,就像序列示例一样,但不关心顺序?或者,为什么这样的模式首先是个坏主意?

How can I write a schema that will validate my xml as does the sequence example, but that does not care for order? Or alternatively why such a schema would be a bad idea in the first place?

推荐答案

请查看:XSD all 和 XSD 序列之间的中间方式

这篇关于<xs:all> 下的元素重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆