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

Element validation based on attribute value? XMLSchema + Schematron?

  • To: xml-dev@l...
  • Subject: Element validation based on attribute value? XMLSchema + Schematron?
  • From: "Andrzej Jan Taramina" <andrzej@c...>
  • Date: Sun, 20 Jan 2002 21:42:02 -0500
  • Organization: Chaeron Consulting Corporation
  • Priority: normal
  • Reply-to: andrzej@c...

schematron attribute value
I have a situation where I would like to validate the text of an element, based 
on the value of an attribute.  

A simple example is using units of measure specified in an attribute in the 
following example: 

<myElement uom="meters">2.5</myElement> <myElement 
uom="feet">9.0</myElement> 

Now assume I want to validate the myElement is always <= 3 meters 
(regardless of the unit of measure.....so it's less than roughly 11 feet). 

There is no way to do this using just a  XMLSchema that I am aware of. 

Seems that embedding Schematron assertions in an <appinfo> tag would 
probably do the trick (and keeps the validation "logic" embedded in the 
XMLSchema document), but is that the best way to handle such validation?  

Are there validation solutions "better" than Schematron for such a 
requirement? 

If I restructure the above example to look like the following: 

<myElement>    
   <feet>9.0</feet> 
</myElement> 

<myElement>
    <meters>2.5</meters> 
</myElement> 

Where myElement is defined in a XML Schema using an xsd:choice as 
follows: 

<xsd:element name="myElement">
   <xsd:complexType>
      <xsd:choice>
         <xsd:element name="feet" type="xsd:decimal"/>                   
         <xsd:element name="meters" type="xsd:decimal"/>
      </xsd:choice>         
   </xsd:complexType> 
</xsd:element> 

Then you could validate the value range using just a XML Schema (using 
restrictions and such). 

This seems a less "natural" construct than the use of attributes (since the 
attribute uom in this example is really metadata), but does have the benefit of 
not requiring external functionality for validation.  

Any thoughts on the pros/cons of a nested-elements approach to this 
validation requirement? 

Would definitely appreciate some ideas/opinions/ruminations/best practices on 
the "best" way to handle such validations. 


Andrzej Jan Taramina
Chaeron Corporation: Enterprise System Solutions
http://www.chaeron.com


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.