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

Re: How to Provide default elements in XMLSchema differentiated with attribute values

From: Jeni Tennison <jeni@jenitennison.com>
Date: Thu, 24 Jan 2002 10:58:09 +0000
Message-ID: <167330345101.20020124105809@jenitennison.com>
To: Rajan Gupta <rgupta99_1999@yahoo.com>
CC: xmlschema-dev@w3.org
Hi Rajan,

> I can write an XMLSchema for Liquids, but how do I enforce that
> elements with water & milk as attribute values are present every
> time an instanc document is created of the schema.

I'm afraid that you can't in XML Schema. If your instance document
used 'water' and 'milk' as the *names* of the elements:

  <FoodItems>
    <water><qty>100</qty></water>
    <milk><qty>50</qty></milk>
    <coke><qty>10</qty></coke>
  </FoodItems>

Then you could represent the constraint in XML Schema. However, to get
the kind of constraint you want, you need to state that a content
model holds elements that share the same name but are of different
types, and that's explicitly disallowed in XML Schema.

You are better off using RELAX NG or Schematron to articulate this
kind of constraint.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Thursday, 24 January 2002 05:58:10 GMT

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