Nikhil
Nikhil

Reputation: 2318

XML Schema(XSD): Is it possible to create a rule/relation for an element based on another element?

I have 2 elements:

  1. Total number of connections
  2. Connections per second.

I would like to enforce the following rules:

Currently I have total connections as following:

<xs:simpleType name="TotalConnections" use="optional" default=1> 
    <xs:restriction base="xs:positiveInteger"> 
        <xs:minExclusive value="0" />
         <xs:maxInclusive value="8000"/> 
    </xs:restriction> 
</xs:simpleType> 

How do I link total connections with cps in my schema?

Upvotes: 0

Views: 90

Answers (1)

Michael Kay
Michael Kay

Reputation: 163675

Expressing the constraint is not possible with XSD 1.0; it can be done in XSD 1.1 using assertions.

<xs:assert test="ConnectionsPerSecond le TotalConnections"/>

Even with XSD 1.1 it's not possible to define default values that are computed rather than constant.

Upvotes: 2

Related Questions