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

Re: constraints - odd question

  • From: Rick Jelliffe <ricko@a...>
  • To: xml-dev@l...
  • Date: Mon, 09 Jul 2001 12:33:12 +0800

odd question
 From: "Simon St.Laurent" <simonstl@s...>

> Suppose I want to create a preferences or properties file where the
> names of the elements correspond to the names of the properties
> involved.  I'm not concerned with validation in the sense that certain
> elements (it's all elements) must be present in a certain order, but
> there may be a different kind of validation needed.
>
> I want to make certain that no elements have the same names as their
> siblings.  Duplication of a property name will lead to overwriting, and
> they want a simple way to warn readers that the duplication has occurred
> before loading the properties file into their particular environment.

This is very simple to do in W3C XML Schema schematas. You can use
an <all> group, if all the elements are required.

If not all the properties are required, in Schematron you can use the
following :
<pattern>
  <rule context="x">
        <report test="count(prop1) &gt; 1"
            >There should not be more than one prop1 in an x</report>
        <report test="count(prop2) &gt; 1"
            >There should not be more than one prop2 in an x</report>
        <report test="count(prop2) &gt; 1"
            >There should not be more than one prop2 in an x</report>
   </rule>
</pattern>

If all the properties are required, then
<pattern>
  <rule context="x">
        <assert test="count(prop1) = 1"
            >There should be one prop1 in an x</assert>
        <assert test="count(prop2) = 1"
            >There should be one prop2 in an x</assert>
        <assert test="count(prop2) = 1"
            >There should be one prop2 in an x</assert>
   </rule>
</pattern>

You might also add the following rules to close the content model

  <rule context="x/prop1 | x/prop2 | x:prop3">
        <assert test="true()"><name/> is allowed</assert>
  </rule>
  <rule context="x/*">
        <report test="true()"><name/> is not allowed</report>
  </rule>

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.