Can this be done in a W3C schema?

G

Gus Gassmann

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.
 
K

keshlam

. 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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top