XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] modelling the business rule "at least one of the elements"

(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]


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

Copyright 1993-2007 XML.org. This site is hosted by OASIS