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

RE: Schema validation question


xml schema preserve dependency

Linda, just RELAX, and get some sleep.

schema:
start = Fruits
Fruits = element Fruits { Fruit+ }
Fruit  = element Fruit  { Apple | Orange  }
Apple  = element Name { 'Apple' }, element Abbrev { 'APL' }
Orange = element Name { 'Orange' }, element Abbrev { 'ORG' }

instance:
<Fruits>
   <Fruit>   
       <Name>Apple</Name>  
       <Abbrev>APL</Abbrev>  
   </Fruit>  
   <Fruit>  
      <Name>Orange</Name>   
      <Abbrev>ORG</Abbrev> 
    </Fruit> 
    
     <!-- invalid:
     <Fruit>  
       <Name>Apple</Name>  
       <Abbrev>ORG</Abbrev> 
     </Fruit>
     -->
</Fruits>



-----Original Message-----
From: Linda Grimaldi [mailto:grimlinda@e...] 
Sent: Tuesday, May 04, 2004 5:18 PM
To: xml-dev@l...
Subject:  Schema validation question


I have been out of the XML world for a little while now, but someone just
asked me a question and I have to admit, it's going to keep me up tonight if
I can't come up with a better solution.  And I'm a little rusty, to boot...

The issue is one of data dependency and validation.  The goal is to enforce
a restriction on pairs of data values- if the data associated with the node
<Fruit><Name> is "Apple", then the value of the sibling node <Fruit><Abbrev>
must be "APL".  Effectively, the goal is to enforce a specific mapping from
one enum into another within an XML document. The only way my associate
could figure to capture this dependency is as follows:

<xs:complexType name="Fruit">
	<xs:annotation>
		<xs:documentation>Defines the valid values for fruit
types</xs:documentation>
	</xs:annotation>
	<xs:choice>
		<xs:element name="APL" type="xs:token" fixed="Apple"/>
		<xs:element name="ORG" type="xs:token" fixed="Orange"/>
		<xs:element name="BAN" type="xs:token" fixed="Banana"/>
		<xs:element name="LEM" type="xs:token" fixed="Lemon"/>
		<xs:element name="GRP" type="xs:token" fixed="Grape"/>
	</xs:choice>
</xs:complexType>

All in all, this strikes me as a very ugly, even offensive, solution.  My
initial response was to forget about the validation- it wasn't worth it.  Is
there a way to preserve the data dependency validation without warping the
instance document as the above schema fragment would require?

Thanks,
Linda

-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an initiative
of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://www.oasis-open.org/mlmanage/index.php>

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.