[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: key constraint question


schematron key
From: "Chiusano Joseph" <chiusano_joseph@b...>
> 
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.