Can this be done in a W3C schema?

Discussion in 'XML' started by Gus Gassmann, Dec 27, 2007.

  1. Gus Gassmann

    Gus Gassmann Guest

    I have the following two elements in a large schema:

    <xs:complexType name="TimeDomainStageVariables">
    <xs:sequence minOccurs="0">
    <xs:element name="var" type="TimeDomainStageVar"
    maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="numberOfVariables"
    type="xs:nonNegativeInteger" use="required"/>
    <xs:attribute name="startIdx" type="xs:nonNegativeInteger"
    use="optional"/>
    </xs:complexType>
    <xs:complexType name="TimeDomainStageVar">
    <xs:attribute name="idx" use="required">
    <xs:simpleType>
    <xs:restriction base="xs:int"/>
    </xs:simpleType>
    </xs:attribute>
    </xs:complexType>

    The idea is to provide a list of which variables belong to which
    stage, and there are two mechanisms for doing this. Is it possible to
    set things up so that the attribute "startIdx" and the sequence of
    <TimeDomainStageVar>s in the first element is mutually exclusive? That
    is, if the user puts startIdx, I'd like the maxOccurs in line 3 above
    to be limited to 0 instead of "unbounded". Can that be done?

    Thanks for any ideas.
     
    Gus Gassmann, Dec 27, 2007
    #1
    1. Advertising

  2. Gus Gassmann

    keshlam Guest

    On Dec 27, 3:05 pm, Gus Gassmann <> wrote:
    >. Is it possible to
    > set things up so that the attribute "startIdx" and the sequence of
    > <TimeDomainStageVar>s in the first element is mutually exclusive?


    XML Schema doesn't support that sort of cross-constraint, except by
    declaring subtypes and explicitly specifying which of the subtypes
    that particular instance is using.... or by declaring two different
    elements for the two variant structures and accepting either at that
    point in the schema.

    Or you may want to consider imposing this constraint in the
    application code (and documentation) rather than the schema. Schemas
    generally shouldn't be expected to provide a complete semantic sanity-
    check; they're closer to "higher-order syntax."

    If portability isn't an issue for you, you *could* consider trying one
    of the alternative schema/constraint languages (Relax, Schematron,
    etc)... but those aren't widely supported, so they're of limited
    practical use (except for pushing the W3C to consider adding
    equivalent features to future generations of XML Schema).
     
    keshlam, Dec 28, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Pilcher

    Can't validate W3C XML meta-schema

    Ian Pilcher, Aug 23, 2005, in forum: Java
    Replies:
    2
    Views:
    540
    Ian Pilcher
    Aug 23, 2005
  2. Markus
    Replies:
    1
    Views:
    1,556
    Markus
    Nov 23, 2005
  3. Frank
    Replies:
    9
    Views:
    1,573
    David Dorward
    May 3, 2004
  4. Steve Jorgensen
    Replies:
    0
    Views:
    561
    Steve Jorgensen
    Aug 9, 2005
  5. Replies:
    1
    Views:
    373
Loading...

Share This Page