OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] key constraint question

[ Lists Home | Date Index | Thread Index ]

From: "Chiusano Joseph" <chiusano_joseph@bah.com>
> 
> What you are trying to do (enforce that there is at least one occurrence
> of element TableB whose "relationship" attribute value is "needed")
> cannot be done with W3C Schema. 
> 
> Someone will be along very shortly to describe how Schematron can
> enforce this.

That's me!

When should you use Schematron?

  1) When your brain is exploding from trying to figure out how to do something
with a grammar-based language
  2) When you are tempted to use a transformation language or general purpose
 language but you would prefer something less messy and convoluted
  3) When the constraints you have belong in some unsettling mysterious layer
  between "schemas" and business rules that your mother did not warn you about
  4) When you are concerned about specification and validation of constraints
  rather than data binding XML and DBMS systems

Schematron is very direct. XPath is a basic skill for XML professionals, so 
Schematron should not impose much learning burdon. Here is the constraint:

<rule context="TableA">
    <assert test="count(TableB[@relationship='needed'])=1" >
        Table A must have one (and only one) TableB with the relationship of "needed". 
    </assert>
</rule>

Actually, I think you can represent your constraint in XML Schemas (someone
will be along very shortly to correct me if I have this wrong :-) :
 * make a complex type for your table B reference
 * make two derived types from that complex type, one with the 
  relationship attribute restricted to "needed", and one with the attribute
  restricted to "needed"
 * in the schema, declare that the first TableB in TableA uses the
  type restrictied to "needed" and that the other use the type restricted
  to "optional".  (In XML Schemas,  subelements with the same name
  can have different types, as long as there is no ambiguity about which
  type would be selected: so  (TableB, TableB*) the two particles
  can have different types.)

Longwinded, eh?  Well, it probably comes down to tools familiarity:
if you are creating XML Schemas all day, then of course you can get
very slick and efficient at it.  If you are doing occassional work only,
I feel your pain. 


Cheers
Rick Jelliffe




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS