views:

31

answers:

2

I have the following XML sequence

<property name="a"  value="x" />
<property name="b"  value="xx" />

I want to limit "a" to a list of values, like [ x, y, z] and "b" to another list like [xx, yy, zz]

Is it possible to do this using XSD, and if it is how?

If this is not possible, how do you recommend to change the XML format in order to make it ready for XSD validation? (I do have more than two property name/value pairs)

A: 

No, it's not possible.

Fyodor Soikin
+1  A: 

XSD accomplishes what you want (conditional validation) using nesting.

So while you can't use XSD to make the values of one attribute conditional upon the values of another (as Fyodor Soikin says in his answer), you can use XSD to make the values of an attribute conditional upon the element itself:

<propertyNameA value="x"/>
<propertyNameB value="xx"/>

In this case each property is its own element, and each "value" attribute has its own enumeration.

It gives you the added benefit of being able to restrict how many of each named property you can have, but the disadvantage is you need to manage more elements.

Depending on the specifics of your situation, using XSD this way might be the best option, or it might be better to implement another system that can do the name/value validation you need.

Welbog
Thanks, anyway reinventing the wheel by inventing another validation system/tool is not a good idea. If possible, repairing the old format and make it XSD ready is much better.
Sorin Sbarnea