W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

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

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 4 Feb 2002 13:16:16 +0000
Message-ID: <12612954071.20020204131616@jenitennison.com>
To: "Test1" <test1@w3.org>
CC: xmlschema-dev@w3.org
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:element name="FooFoo" minOccurs="2" maxOccurs="2">
        <xs:union memberTypes="xs:integer xs:string" />

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.



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

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:55 UTC