views:

165

answers:

2

Is there any reason why <xs:group> cannot appear inside <xs:all>, but only inside <xs:sequence>?

Let's see an example. Say, there is a list of tags (<a> to <d> and <e> to <f> - see example below) which do not appear in any particular order, but always wrapped into another object (either <foo> or <bar>); <foo>={<a>, <b>, <c>, <d>}; <bar>={<e>, <b>, <c>, <f>}:

<foo>
  <a>a1</a>
  <b>b1</b>
  <c>c1</c>
  <d>d1</d>
</foo>

<foo>
  <d>d2</d>
  <b>b2</b>
  <c>c2</c>
  <a>a2</a>
</foo>

<bar>
  <e>e3</e>
  <b>b3</b>
  <c>c3</c>
  <f>f3</f>
</bar>

I want to extract tags <b> and <c> into xs:group and use <xs:group ref="..."> when defining complexType of <foo> and <bar> in the XSD. However, due to the restriction mentioned above, this is not possible.

What would you suggest as a workaround for the given problem? Chances are, I am doing something stupid, but again why is this incorrect?

A: 

I can't say why this limitation exists, although I can see that the possible combinations of a fully-featured <group> (with nested <choice> and <all>) inside another <all> might be a bit confusing to the developer (well, me anyway) and especially to users.

As a workaround I'll suggest what you've probably already come up with: that is, to declare another <complexType> for <b> and <c> and to use that inside your <foo> and <bar>:

  <xs:complexType name="bcType">
    <xs:all>
      <xs:element name="b" type="xs:string" />
      <xs:element name="c" type="xs:string" />
    </xs:all>
  </xs:complexType>

  <xs:complexType name="foo">
    <xs:all>
      <xs:element name="d" type="xs:string" />
      <xs:element name="a" type="xs:string" />
      <xs:element name="bc" type="bcType" />
    </xs:all>
  </xs:complexType>

  <xs:complexType name="bar">
    <xs:all>
      <xs:element name="f" type="xs:string" />
      <xs:element name="e" type="xs:string" />
      <xs:element name="bc" type="bcType" />
    </xs:all>
  </xs:complexType>
Ben M
I would definitely use this approach, however then I would have to rename "b" and "c" elements into "bc" which is not an appropriate solution due to legacy reasons. I need to name them "b" and "c" and that's why I use xs:group.
mindas
Then you'll probably have to forego using <group> -- unfortunately!
Ben M
A: 

The deterministic content rule is the reason for the restriction. If you want a full understanding, read van der Vlist's book or the standard.

bmargulies