I have a project whose main goal is to validate xml against xsd.
I use Java 1.8 from Adoptium and I initiate the SchemaFactory this way:
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI, "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory", null)
When I have the following xsd:
<xs:complexType name="PersonType">
<xs:sequence>
<xs:element minOccurs="0" name="NickName"/>
<xs:element minOccurs="0" name="Address"/>
<xs:element name="Surname"/>
<xs:element minOccurs="0" name="Occupation"/>
</xs:sequence>
</xs:complexType>
Using the following xml:
<Person/>
returns the following error:
cvc-complex-type.2.4.b: The content of element 'Person' is not complete. One of '{"namespace":NickName, "namespace":Address, "namespace":Surname}' is expected.
This error is misleading since the user should only provide the mandatory element Surname
but it's not clear from the error he/she gets.
So, how can I make the validation to return only the mandatory fields in the error description?
I tried to modify the source code of the library but this is impossible since this is Java embedded and also the code which decides these fields has a strange logic.