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

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 UTC