Wenhao Ji
Wenhao Ji

Reputation: 5151

Is there any way in xml schema to let an attribute always be greater than another one in an xml element?

Here is the xml:

<range from="100" to="200"/>

So, how to write an xsd to ensure that the attribute to is always larger than from?

Upvotes: 0

Views: 1046

Answers (3)

Octavian
Octavian

Reputation: 444

Here is a sample to see how you can add an XSD 1.1 assert in your case:

<xs:complexType>
    <xs:attribute name="to" type="xs:integer"/>
    <xs:attribute name="from" type="xs:integer"/>
    <xs:assert test="@to > @from"/>
</xs:complexType>

In the "test" attribute from the "assert" element you can introduce an XPath 2.0 expression.

Upvotes: 1

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25034

In XSD 1.1, you can use an assertion on the type of 'range' to impose that constraint. In XSD 1.0, the constraint is not expressible.

Upvotes: 1

Pradeep Pati
Pradeep Pati

Reputation: 5919

Schema, by definition will just define the schema of the document, not validate the conditional data. You have to do that in your application.

Upvotes: 1

Related Questions