[
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
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
|