OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Element validation based on attribute value? XMLSchema + Schematron?

[ Lists Home | Date Index | Thread Index ]

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 

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 

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



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

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

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


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

Copyright 2001 XML.org. This site is hosted by OASIS