Why can't I put xs: everything inside the xs: sequence?

I'm still a bit new to XML Schema and I'm trying to do something like this in Relax NG Compact:

test = element test{
element A {text},
element B {text},
(element C {text}? &
element D {text}?)
}

      

This means that the test item contains A, then B, then in any order C and D, which are optional.

As I see it, I should just put

<xs:element name="test">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="A"/>
            <xs:element name="B"/>
            <xs:all>
                <xs:element name="C"/>
                <xs:element name="D"/>
            </xs:all> 
        </xs:sequence>
    </xs:complexType>
</xs:element>

      

But that won't let me put <xs:all>

inside <xs:sequence>

. Utterance

s4s-elt-must-match.1: The content of the "sequence" must match (abstract ?, (element | group | selection | sequence | any) *). The problem was found since: everything.

So I tried to do <xs:all>

from the <xs:sequence>

following:

<xs:element name="test">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="A" />
                <xs:element name="B"/>
            </xs:sequence>
            <xs:all>
                <xs:element name="C"/>
                <xs:element name="D"/>
            </xs:all> 
        </xs:complexType>
    </xs:element>

      

But now it still doesn't work saying

s4s-elt-invalid-content.1: The content '#AnonType_test' is invalid. All is invalid, inappropriate, or too common.

So, I am confused because it seems so simple, but I don't understand how to do it.

+3


source to share


2 answers


Your confusion is understandable. The problem is that XSD design is irregular, and wrong designs often violate our expectations.

Here's a workaround, which is unfortunately more verbose and impractical for more elements to be rearranged:



  <xs:element name="test">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="A"/>
        <xs:element name="B"/>
        <xs:choice minOccurs="0">
          <xs:sequence>
            <xs:element name="C"/>
            <xs:element name="D" minOccurs="0"/>
          </xs:sequence>
          <xs:sequence>
            <xs:element name="D"/>
            <xs:element name="C" minOccurs="0"/>
          </xs:sequence>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

      

Another workaround is ordering; that any order is often not important in practice.

+1


source


One of the design reasons, in my opinion, is that the ability to create groups without procurement procedures ( all

) and ordered ( sequence

, choice

, ...) will increase the complexity of the model validation XML-schema in terms of algorithms and put a big burden on developers.

But moreover, in some cases related to, for example, optional elements, this can also lead to ambiguity when matching elements with particles (i.e. declarations of elements within model groups), introducing non-determinism or implementation dependency, which is not desirable for interoperability.



The benefits of such restrictions outweigh their overall costs. Most users of XML Schema use sequence

and choice

enforce ordering (see kjhughes example).

Relax NG (which I don't know) may use a different model to describe the content of elements, and this model is probably compatible with various design choices.

0


source







All Articles