I have xml files:
<Parent>
<Child1 ... />
<Child2 ... />
...
<Child1 ... />
<Child1 ... />
<Parent>
Where Clild1 and Child2 – childrens of Parent abstract class.
That is, the question was:
How to set a validation scheme for the collection that can have any number of elements different types?
Best regards!
To illustrate how this works let’s use a simplified version of your example input.
<Parent>is the first element so validates.<Child1>. Since<Child1>is the first element in thechoiceblock it validates.<Child2>element. Since<Child2>is next it also validates.</Parent>so the validator checks it against thechoiceblock since it can occur an unlimited number of times asmaxOccurs=unbounded.<Child1>element which validates.<Child2>element which doesn’t exist so it finishes thechoiceblock.</Parent>so the validator checks it against thechoiceblock since it can occur an unlimited number of times asmaxOccurs=unbounded.<Child1>element which validates.</Parent>which validates.Since
minOccurs=0this also allows for the case where there is0occurrences of a<Child1>or<Child2>element. XML schema elements inherit the properties of their parent elements unless explicitly declared. In this case, since we did not declare a minOccurs property for either<Child1>or<Child2>this is the equivalent of<xs:element minOccurs="0" name="Child1"/>and<xs:element minOccurs="0" name="Child2"/>.