W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2008

Conditional Schema Processing

From: Zac Harvey <zachary.harvey@gmail.com>
Date: Fri, 5 Dec 2008 12:11:10 -0500
Message-ID: <72032db40812050911y661f3807n5f788194f7ec337a@mail.gmail.com>
To: xmlschema-dev@w3.org
This may be bad design, so if it is, then I guess what I'm looking for is an
elegant alternative solution. However I don't believe the following to be a
product of poor design, and so the following question should apply:

I want a particular element, <*widget*> to force the user to define a
*foo*attribute, which will be an enum type of three potential values:
*me*, *you* or *us*. For example:

<widget foo="me" />
<widget foo="you" />
<widget foo="us" />

Would all be legal <widget> instantiations. And so I have the following so
far in my XSD:

*<xs:element name="widget" minOccurs="1" maxOccurs="unbounded">
        <xs:attribute name="foo" type="xs:string" use="required">
                <xs:restriction base="xs:string">
**                    **<xs:enumeration value="me" />
**                    **<xs:enumeration value="you" />
**                    **<xs:enumeration value="us" />
**                **</xs:restriction>
**            **</xs:simpleType>

**        **<xs:sequence>
            <!-- No definition yet ... -->
**        **</xs:sequence>
What I am looking for is the ability to define <widget>'s sequence based on
the value of foo.  If foo="me" I want it to contain, say, an <apple>
element. Else if it is "you" or "us" I want it to contain an <orange> child
element.  So for example:

<widget foo="me">

<widget foo="us">

I have been pouring through the tutorials and cannot find a way to include
this conditional functionality...
Received on Friday, 5 December 2008 17:31:50 UTC

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