[
Lists Home |
Date Index |
Thread Index
]
> MessageFrom: Prasad G S K
> >Can I define this kind of restriction/dependency in XSD files?
In general, you cannot do value-to-structure constraints in XSD (WXS).
Schematron is a schema language, undergoing ISO standardization,
which is designed to complement WXS, DTDs and RELAX NG.
It is usually good for all the kinds of constraints that sit between
the simple containment constraints and the application-specific
business rules.
Your constraints would be specified in Schematron like this:
<rule context="prop1[text()='ABC']" >
<assert test="following-sibling::*[1][self::prop2]">
When the value of "prop1" is ABC then "prop2" should follow "prop1"
</assert>
</rule>
<rule context="prop1[text()='XYZ']" >
<assert test="following-sibling::*[1][self::prop3]">"
When the value of "prop1" is XYZ then "prop3" should follow "prop1"
</assert>
</rule>
Note that you have expressed your constraints in a form that
can be used directly to drive the assertions you want to make.
Rather than trying to squeeze them into the form of a grammar,
you can just use translate your XPaths fairly directly. This is
commonly the case with Schematron assertion.
The XPaths may seem strange, but they are a good thing to learn
for any developer working in XML. XPaths assertions tend to complement
grammar-based schemas, because what is trivial to express in one
is often difficult or impossible to express in the other.
RELAX NG is good for some important value-to-structure constraints,
but only regular ones where a value helps determine the path
through a content model. If you do not wish to give up XSD (WXS)
or you may need other kinds of constraints (value-to-value, structural
constraints between different branches or different depths of the
document) then you may find it easier to put in Schematron
early and augment it with constraints as they become apparant.
There is a free drag-and-drop validator for XSD, RELAX NG and Schematron
for Windows at http://www.topologi.com/
Cheers
Rick Jelliffe
Topologi Pty. Ltd.
|