I have the below XML Schema:
<xs:element name="_links">
<xs:complexType>
<xs:sequence>
<xs:element name="self">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="href" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="next">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="href" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="prev">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="href" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
A specific XML document I am validating does not have a "next" field in it (although some documents can). When I load this document I am receiving the error:
Error validating source XML against schema - The element '_links' in namespace 'http://www.orbis-software.com/WebSvcCon' has invalid child element 'prev' in namespace 'http://www.orbis-software.com/WebSvcCon'. List of possible elements expected: 'next' in namespace 'http://www.orbis-software.com/WebSvcCon'.
As per the XSD the "next" element is set to minOccurs=0 making it optional, so why I am receiving the error?
In your schema the contents of the
_linkselements is defined inas a sequence of three elements, namely
self,nextandprev. None of these elements is optional as none of them has amixOccurs="0", there is only amixOccurs="0"on the content of each of those elements as they can can contain 0 to unboundedhrefelements.So
<_links><self/><next/><prev/></_links>is possible but you can't leave out any of those three elements.