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

Re: Defining content based on attributes

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 22 Sep 2003 15:21:24 +0100
Message-ID: <2242227594.20030922152124@jenitennison.com>
To: "Steven Baker" <steven.baker@adazzle.com>
Cc: xmlschema-dev@w3.org

Hi Steven,

> I am trying to develop a schema for some XML and need to be able to
> define what the content of the "input_value" and "output_value" can
> be depending upon the value of the field attribute "name" AND the
> attribute "type" An example for this XML would be that if the type
> is "text" then the input_value is of type xsd:string - if the name
> is order_no I then want a restriction to say that this must not be a
> blank string.
> I assume this is all very possible but am struggling to see how -
> the examples I have seen all refer to XML structures with unique
> element names (not what I want for processing reasons and
> flexibility in other areas of the design).

Unfortunately, you assume wrong. XML Schema doesn't support these
kinds of "co-occurrence constraints". The usual recommendations are:

(a) Come to terms with the fact that no schema will be able to test
every aspect of a markup language, and console yourself that at least
an XML Schema schema can test more than a DTD.

(b) Change your markup language design so that either (1) each element
name is associated with a unique type or (2) you use the single
xsi:type attribute to indicate the type of an element.

(c) Augment your XML Schema schema with a Schematron schema that can
test the extra constraints.

(d) Write an XSLT transformation that turns your markup language into
a markup language as in (b); whenever you want to validate a document
in your markup language, run the transformation on it and validate
against the resulting markup language.

(e) Switch to RELAX NG, which does support these kinds of constraints.



Jeni Tennison
Received on Monday, 22 September 2003 10:21:40 UTC

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