XML schema for testing meaning and applying additional constraints
I have the following case: All boats have a type of boat such as shark, yacht, etc. I need to register the name of the boat type as well as how many feet the boat has, but this is where the problem arises. If the user enters a shark, I need to confirm that it is 15-30 feet, if he enters yatch, for example, it should be between 30-60.
Any help on this?
<boat>
<type>shark</type>
<foot>18</foot> //validates
</boat>
<boat>
<type>shark</type>
<foot>14</foot> //fails
</boat>
<boat>
<type>AnyOtherBoat</type>
<foot>14</foot>//validates since its another type of boat than shark and yatch
</boat>
Help rate! thanks
0
a source to share
2 answers
To answer your question: No, you cannot do this in XML Schema.
- First, you cannot use values to choose which constraints to apply (but you could use elements like
<shark>
) - Second, you cannot do arithmetic tests (but you can use a regex to specify valid strings ... so you can hack it.)
+1
a source to share
Schematron ("a language for making assertions about templates found in XML documents") may be capable of doing what you want. It allows you to specify additional rules that cannot be expressed in a correct XML schema definition (XSD, RelaxNG).
Here are some articles to get you started:
+3
a source to share