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

Re: modelling the business rule "at least one of the eleme

  • From: "Rick Jelliffe" <rjelliffe@a...>
  • To: xml-dev@l...
  • Date: Wed, 22 Nov 2006 16:17:29 +1100 (EST)

xsd at least one element
(resent)

XSD provides a content type <ALL> which does what you need, I think.

If you wanted the constraint that you could have more than one of each,
but at least one of each, you would be looking at a really nasty content
model, something like the following:

  (a+,
          (b,
                   (a, (a |b)*)?, c)
                 | (b, (a |b)*)?, c)
                 |  c )
         |
          (c,
                   (a, (a |c)*)?, b)
                 | (c, (a |c)*)?, b)
                 |  b ))
|
   (b+,

          (a,
                   (a, (a |b)*)?, c)
                 | (b, (a |b)*)?, c)
                 |  c )
         |
          (c,
                   (b, (b |c)*)?, a)
                 | (c, (b |c)*)?, a)
                 |  a ))
|
   (c+,

          (a,
                   (a, (a |c)*)?, b)
                 | (b, (a |c)*)?, b)
                 |  b )
         |
          (b,
                   (b, (b |c)*)?, a)
                 | (c, (b |c)*)?, a)
                 |  a )),

  (a | b | c)*
which would take about 125 XSD elements, I think.

I think XSD 1.1 improves ALL to cope with this situation better.

Cheers
Rick Jelliffe

N.B. Using Schematron, you would say for the ALL case

<rule context="parent">
  <assert test="count(a)=1">Parent must have one child a</assert>
  <assert test="count(b)=1">Parent must have one child b</assert>
  <assert test="count(c)=1">Parent must have one child c</assert>
  <assert test="count(*) = count(a) + count(b) + count(c)">
   The parent  can only contain a, b and c elements
  </assert>
</rule>

And the equivalent Schematron schema for the 125 element XSD rule is

<rule context="parent">
  <assert test="count(a) &gt; 0">Parent must have at least one child
a</assert>
  <assert test="count(b) &gt; 0">Parent must have at least  one child
b</assert>
  <assert test="count(c) &gt; 0">Parent must have at least  one child
c</assert>
  <assert test="count(*) = count(a) + count(b) + count(c)">
   The parent  can only contain a, b and c elements
  </assert>
</rule>

125 versus 5...





[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


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.