Suppose I have this XmlSchema fragment:
<xs:element name= "A">
<xs:complexType>
<xs:sequence>
<xs:element ref="A1" maxOccurs="1"/>
<xs:element ref="A2" maxOccurs="unbounded"/>
<xs:element ref="A3" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
I use the XmlSchemaValidator.GetExpectedParticles() method to cycle into A’s children. Because the complexType is a Sequence, to validate a sibling I need to validate the previous one, exit from the context and only then the GetExpectedPartciles() will return the next sibling.
So when I am in A1 item of the list, I call these line of code:
validator.ValidateElement("A1", null, null); --> validate and enter in the Context of A1
validator.ValidateEndOfAttributes(null); --> End the validation of Attributes
validator.SkipToEndElement(null); --> Exit from the context; only when the ComplexType is a Sequence
When I reach the A2 element, the GetExpetectedParticles returns, as in a loop, the same Element A2 and I cannot reach the A3 element (or I do not know how to do). I suppose this is because the maxoccurs is unbounded.
So the question is How can I jump to the next sibling A3?
GetExpectedParticles() does return A3 along with A2. So if you want get out of the loop, just continue validating the next item in the array, and not call GetExpectedParticles() again if current MaxOccursString = “unbounded”.