문제

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)

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top