Re: Two elements FooFoo with different types in a sequence? Is this possible?

Hi Michi,

> I want do this:
>
> <xsd:complexType name="Foo">
>
>     <xsd:sequence>
>          <xsd:element name="FooFoo" type="xsd:string"/>
>          <xsd:element name="FooFoo" type="xsd:integer"/>
>     </xsd:sequence>
>
> </xsd:complexType>

I'm afraid that you can't do that in XML Schema because all the
elements with the same name in a content model must have the same type
as well. You can do:

<xs:complexType name="Foo">
  <xs:sequence>
    <xs:element name="FooFoo" minOccurs="2" maxOccurs="2">
      <xs:simpleType>
        <xs:union memberTypes="xs:integer xs:string" />
      </xs:simpleType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

which says that there must be two FooFoo elements, which can either
contain integers or strings. But you can't say that the FooFoo element
with an integer value must come after the FooFoo element with the
string value, nor that one must be a string and the other an integer.

Another workaround might be to add xsi:type attributes to the instance
document, to indicate that the first FooFoo is a string and the second
an integer, prior to validation. You could do this with an XSLT
transformation for example.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Monday, 4 February 2002 08:16:22 UTC