0

I know there is another discussion on this topic xsd validation to allow unexpected elements

But I added the and it still doesn't work.

Here is my XSD:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="member">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="card">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="cardNumber">
                                    <xs:simpleType>
                                        <xs:restriction base="xs:string">
                                            <xs:length value="16"/>
                                        </xs:restriction>
                                    </xs:simpleType>
                                </xs:element>
                                <xs:any minOccurs="0"/>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>

Here is my code to run the validation in an interceptor (using CXF)

final File xsd;
final Schema closeSchema;
try {
    closeSchema = SchemaFactory.newInstance(xsdAnnotation.schemaLanguage()).newSchema(xsd);
} catch (final SAXException e) {
    throw new IllegalStateException(e);
}

// get the payload in the request body 
final String payload = (String) context.getParameters()[i];
closeSchema.newValidator().validate(new StreamSource(new StringReader(payload)));

well, I removed some other irrelevant logic, but the validation process works

If I pass

<member>
    <card>
        <cardNumber>1234567890123456</cardNumber>
    </card>
</member>

the validation works; however, if I pass

<member>
    <card>
        <cardNumber>1234567890123456</cardNumber>
        <memberType>??</memberType>
    </card>
</member>

It gives me the exception

"org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 75; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'memberType'."

Community
  • 1
  • 1
sowen
  • 1,090
  • 9
  • 28

1 Answers1

0

Ah, I found the answer. it should be

<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>

this question is duplicate to org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'ReceiptTime'

Community
  • 1
  • 1
sowen
  • 1,090
  • 9
  • 28