Wednesday, 20 July 2011

xs:all vs xs:choice - counter-intuitive but technically correct

imagine you need to validate the following xml piece:
<myRoot>
<SomeOne></SomeOne>
<SomeTwo>
<blah></blah>
<boo></boo>
<moo name="duck">hdhdh</moo>
<moo name="suck">flkfkfk</moo>
<moo name="buck">jsjsj</moo>
<zoo></zoo>
</SomeTwo>

<SomeTwo>
<blah></blah>
<moo name="duck">733737</moo>
<zoo>baaaaa</zoo>
</SomeTwo>
</myRoot>

xs:all will break as it will not allow multiple moo elements
xs:choice maxOccours="unbounded" will work! even though by its name you may assume that it is, well, a CHOICE but saying that max occurs is unbounded it will allow multiple moo elements!

No comments:

Post a Comment