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

RE: Conditional xml Schema


xml schema conditional constraint
XSD supports this type of behaviour in various ways.

One way is to define a base type (fruit) and extend it with other types (apple, orange). Then when defining the container element, you would define it as having children of type fruit. The instance document could incorporate either type.

Another way is to use the choice element in your schema. It matches one of a specific list of types. To have several fruit (each of which might be apple or orange) you can use the minOccurs and maxOccurs attributes on the choice.

-Erik

> -----Original Message-----
> From: Ramkumar Menon [mailto:ramkumar.menon@g...] 
> Sent: June 11, 2006 2:10 PM
> To: Joe Schaffner
> Cc: Jirka Kosek; Jagdishwar B; xml-dev@l...
> Subject: Re:  Conditional xml Schema
> 
> Cross field constraints are better off described thru rule 
> based validation languages like schematron. Use this in 
> conjunction with the XSD to enable cross field validation on fields.
> 
> <pattern name="checkMangoOrApple">
>   <rule context="Fruit">
>      <assert test="@myAttr='Apple' and elementApple1>If 
> myAttr is apple, elementApple1 should be present"/>
>      <assert test="@myAttr='Mango' and elementMango1>If 
> myAttr is mango, elementMango1 should be present"/>
>   </rule>
> </pattern>
> 
> 
> 
> On 6/11/06, Joe Schaffner <schaffner.joe@g...> wrote:
> > Why don't you define a Mango element and an Apple element, 
> each with 
> > their own structure? I'll bet there is even a way to define a Fruit 
> > element, then derive an Apple and a Mango from Fruit. Then 
> you would 
> > instantiate either type of fruit, Apple or Mango, and get 
> the proper 
> > structure.
> > Joe
> > http://modern-greek-verbs.tripod.com/agv/
> > PS
> > It looks like you are trying to use the attribute to name 
> the element 
> > type, which would be unnecessary, and it would surprise me 
> if xsd -- 
> > or any schema definition language -- would attribute class 
> semantics 
> > to the arrtibutes you create arbitrarily. You are trying to 
> place your 
> > metadata in the data domain.
> >
> > On 6/11/06, Jirka Kosek <jirka@k...> wrote:
> > > Jagdishwar B wrote:
> > >
> > > > Is it possible to define the xml schema (xsd) 
> conditionally based 
> > > > on certain values.
> > >
> > > No. You have to use RELAX NG or Schematron to express 
> such constraints.
> > >
> > > --
> > > ------------------------------------------------------------------
> > >   Jirka Kosek     e-mail: jirka@k...     http://www.kosek.cz
> > > ------------------------------------------------------------------
> > >   Profesionální školení a poradenství v oblasti technologií XML.
> > >      Podívejte se na náš nově spuštěný web http://DocBook.cz
> > >        Podrobný přehled školení http://xmlguru.cz/skoleni/
> > > ------------------------------------------------------------------
> > >                    Nejbližší termíny školení:
> > >        ** DocBook 15.-17.5.2006 ** XSL-FO 12.-13.6.2006 **
> > >     ** XSLT 23.-26.10.2006 ** XML schémata 13.-15.11.2006 **
> > > ------------------------------------------------------------------
> > >   http://xmlguru.cz    Blog mostly about XML for English readers
> > > ------------------------------------------------------------------
> > >
> > >
> > >
> > >
> >
> 
> 
> --
> Shift to the left, shift to the right!
> Pop up, push down, byte, byte, byte!
> 
> -Ramkumar Menon
>  A typical Macroprocessor
> 
> 

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.