简体   繁体   English

无序xsd:所有元素后跟另一个元素

[英]Unordered xsd:all elements followed by another element

How can I write an XSD for the following XML? 如何为以下XML编写XSD?

<A></A>
<B></B>
<C></C>
<D></D>
<E></E>
<E></E>

A,B,C,D just have zero or one . A,B,C,D仅具有零或一 And they don't have sequence. 而且他们没有顺序。 It could be D,C,B,A . 可以是D,C,B,A And in the very end, there are one or more E element(s). 最后,有一个或多个E元素。

I have tried multiple ways, but can't get it done. 我尝试了多种方法,但无法完成。

You're blocked by a non-orthogonality of XML Schema. 您被XML Schema的非正交性所阻塞。 You'd think that the following should work: 您认为以下方法应该有效:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="top">
    <xs:complexType>
      <xs:sequence>
        <xs:all>
          <xs:element name="A" minOccurs="0"/>
          <xs:element name="B" minOccurs="0"/>
          <xs:element name="C" minOccurs="0"/>
          <xs:element name="D" minOccurs="0"/>
        </xs:all>
        <xs:element name="E" minOccurs="1" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

However, it does not. 但是,事实并非如此。 XSD's xs:all construct is a second-class citizen; XSD的xs:all构造是一等公民。 it cannot appear in a xs:sequence . 它不能出现在xs:sequence

Recommendation : Drop the "any order" allowance from your requirements: 建议 :从您的要求中删除“任何订单”津贴:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="top">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="A" minOccurs="0"/>
        <xs:element name="B" minOccurs="0"/>
        <xs:element name="C" minOccurs="0"/>
        <xs:element name="D" minOccurs="0"/>
        <xs:element name="E" minOccurs="1" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Allowing any order of elements ends up being less important in practice than in theory, especially given non-orthogonality such as the above and the potential for clashes with Unique Particle Attribution . 实际上,允许任何顺序的元素实际上在实践中都没有理论上的重要,特别是考虑到非正交性(例如上述情况)以及具有唯一粒子归因可能发生冲突的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM