W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2002

Re: Beginner question : complex cross field/attribute validation possible ?

From: Jeni Tennison <jeni@jenitennison.com>
Date: Sun, 11 Aug 2002 16:05:33 +0100
Message-ID: <148302478841.20020811160533@jenitennison.com>
To: "Frank Langel" <frank.langel@webmethods.com>
CC: xmlschema-dev@w3.org

Hi Frank,

> i looked into the XML Schema specs, but i am not sure if a
> validation rule such as
>
> - for instance : if field a==21 and b==32 and field x==field z then
> c must be not null)
>
> can be expressed in XML Schema ?

No, it can't. This is what's known as a co-occurrence constraint,
where the values or presence of particular elements or attributes
influence the value of another element or attribute (or whether it can
be present). It's one of the areas where XML Schema is particularly
weak.

However, you can embed Schematron rules in your XML Schema to test
this kind of thing. Schematron rules use XPath syntax, so your test
might be something like:

  <sch:report test="(a = 21 and b = 32 and x = z) and
                    not(string(c))">
    a is 21, b is 32, x equals z, but c doesn't have a value.
  </sch:report>

[Here assuming that "c must be not null" means "c must have a string
value".]

Have a look at Topologi's Schematron validator and Eddie's description
of how to incorporate Schematron into XML Schema at
http://www.topologi.com/public/Schtrn_XSD/Paper.html

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Sunday, 11 August 2002 11:05:39 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:34 GMT