[Home] [By Thread] [By Date] [Recent Entries]

  • From: "John Avery" <j.avery@b...>
  • To: <xml-dev@l...>
  • Date: Fri, 22 Dec 2006 12:08:11 +1100

I have a schema representing a message which has two parts in sequence,
I am trying to describe a specialisation of that message which imposes
certain constraints on the two parts of the message. Effectively if the
message has a type A part one it needs a type A part two, if it has a
type B part one it needs a type B part two, etc.

It seems to me that the logical way to express this would be:

<xsd:complexType name="specialisationMessage.CONTENT">
  <xsd:complexContent>
    <xsd:restriction base="message.CONTENT">
      <xsd:choice>
        <xsd:sequence>
          <xsd:element ref="partOne.TypeA"/>
          <xsd:element ref="partTwo.TypeA"/>
        </xsd:sequence>
        <xsd:sequence>
          <xsd:element ref="partOne.TypeB"/>
          <xsd:element ref="partTwo.TypeB"/>
        </xsd:sequence>
      </xsd:choice>
    </xsd:restriction>		
  </xsd:complexContent>
</xsd:complexType>

<xsd:element name="specialisationMessage"
type="specialisationMessage.CONTENT" substitutionGroup="message"/>

Where message has the type:

<xsd:complexType name="message.CONTENT">
  <xsd:complexContent>
        <xsd:sequence>
          <xsd:element ref="partOne"/>
          <xsd:element ref="partTwo"/>
        </xsd:sequence>
      </xsd:choice>
    </xsd:restriction>		
  </xsd:complexContent>
</xsd:complexType>

And where partOne.TypeA and partOne.TypeB are valid restriction of
partOne, and partTwo.TypeA and partTwo.TypeB are valid restrictions of
partTwo.

Yet when I validate this document I got message informing me that I I
cannot restrict a sequence with a choice, a fact verified by the XML
Schema documentation. So (finally) my question. How can i express this
restriction?

I can't say:


<xsd:complexType name="specialisationMessage.CONTENT">
  <xsd:complexContent>
    <xsd:restriction base="message.CONTENT">
      <xsd:sequence>
        <xsd:choice>
          <xsd:element ref="partOne.TypeA"/>
          <xsd:element ref="partOne.TypeB"/>
        </xsd:choice>
        <xsd:choice>
          <xsd:element ref="partTwo.TypeA"/>
          <xsd:element ref="partTwo.TypeB"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:restriction>		
  </xsd:complexContent>
</xsd:complexType>

as it allows type A and B messages to be mixed. 

ANy help would be much appreciated.

Regards,

John Avery


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member