W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2003

Re: Schema validation:

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 4 Nov 2003 10:27:02 +0000
Message-ID: <125866591472.20031104102702@jenitennison.com>
To: "Srinivasan, Sriram" <SSrinivasan@filenet.com>
Cc: xmlschema-dev@w3.org

Hi Sriram,

> I have to validate the xml so that a Parameter element can have either a
> Value attribute or a Values element, not both and atleast one of them.
> Is there a way to specify it in xml schema. 

No. XML Schema can't do test co-occurrence constraints.

You're probably best off using a Schematron schema to supplement your
XML Schema schema. You could do reasonably sophisticated validation
with a Schematron schema, for example:

<sch:rule context="Parameter">

  <sch:assert test="@Value or Values">
    The parameter must have a Value attribute or a Values child.

  <sch:report test="@Value and Values">
    The parameter must not have a Value attribute and a Values child.

  <sch:report test="substring(@Type, string-length(@Type) - 1) = '[]'
                    and @Value">
    If the type of a parameter is an array then it must not have a
    Value attribute.

  <sch:report test="substring(@Type, string-length(@Type) - 1) = '[]'
                    and not(Values)">
    If the type of a parameter is an array then it must have a Values
    child element.


<sch:rule context="Values/Value">
  <sch:assert test="@Type =
                    substring(../../@Type, 1, string-length(@Type) - 2)">
    The Type attribute must have the same value as the type of the

Given that you know all the possible types that are allowed, RELAX NG
would also enable you to test your XML quite thoroughly.



Jeni Tennison
Received on Tuesday, 4 November 2003 05:29:25 UTC

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