views:

87

answers:

2

Is there any schema language for XML that allows for specifying a constraint that there can be no cyclic references between elements.

As a toy example:

<animal name="A" eats="B">
<animal name="B" eats="C">
<animal name="C" eats="D">

would validate, but

<animal name="A" eats="B">
<animal name="B" eats="C">
<animal name="C" eats="D">
<animal name="D" eats="A">

would not validate.

+1  A: 

You could use schematron, and then post the same question as an xslt/xpath problem.

Pete Kirkham
Cyclic references like these cannot be validated with Schematron. You could write an XSLT stylesheet to implement the validation, but like @bart-schuller said, you could use any language your comfortable with.
jelovirt
+2  A: 

There are as far as I know no schema languages that are designed to enforce this kind of constraint. If it's possible in a schema language, it'd probably be Schematron. The schema wouldn't be pretty.

To me, that says you shouldn't try to do this using a schema language. Take any programming language that you're comfortable with and code up the constraint in easy to read code. It will be shorter and more understandable than any schema based version.

Bart Schuller
:-) Yup, actually I had started validating this constraint using code when it occurred to me that perhaps some "better"/"proper" way of doing it with a schema language existed.
Atlas1j
Can't be done with Schematron either.
jelovirt