Search code examples
xmlxsdxsd-validationsaxparseexceptionxml-error

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'oai-identifier'. How to fix this?


I have the static XSD schema, which I want to use to validate XML response against from an OAI-PMH endpoints.

It is said there that the schema is already validated.
Yet, when I try to validate XML response from a random OAI-PMH endpoint, such as this one:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="static/style.xsl"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
    <responseDate>2019-07-29T13:29:04Z</responseDate>
    <request verb="Identify">https://repository.lib.ncsu.edu/oai/driver</request>
    <Identify>
        <repositoryName>NCSU Repository</repositoryName>
        <baseURL>https://repository.lib.ncsu.edu/oai/driver</baseURL>
        <protocolVersion>2.0</protocolVersion>
        <adminEmail>[email protected]</adminEmail>
        <earliestDatestamp>2006-11-10T15:53:37Z</earliestDatestamp>
        <deletedRecord>transient</deletedRecord>
        <granularity>YYYY-MM-DDThh:mm:ssZ</granularity>
        <description>
            <oai-identifier xmlns="http://www.openarchives.org/OAI/2.0/oai-identifier"
                            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai-identifier http://www.openarchives.org/OAI/2.0/oai-identifier.xsd">
                <scheme>oai</scheme>
                <repositoryIdentifier>repository.lib.ncsu.edu</repositoryIdentifier>
                <delimiter>:</delimiter>
                <sampleIdentifier>oai:repository.lib.ncsu.edu:1840.20/1234</sampleIdentifier>
            </oai-identifier>
        </description>
    </Identify>
</OAI-PMH>

I get this exception:

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

I have no clue why does it happen and relevant threads didn't help me. Please help me.


Solution

  • Although xsd:any will basically allow any XML element, there are variations of strictness given by its @processContents attribute. In this case, @processContents is strict, which means that any defined element may appear there. Your error message is indicating that it can find no such XSD definition for the oai-identifier element. You can fix this by doing one of the following:

    1. change the XML to present a defined element in that spot;
    2. change the XSD xsd:any/@processContents to lax or skip;
    3. provide the validating XML parser access to the definition of oai-identifier.

    See also: processContents strict vs lax vs skip for xsd:any

    Note: I was able to successfully validate your posted XML without modification. I suggest that you try again, making sure that the validator can access each of the required XSDs (including any referenced XSDs, transitively). If you have an XML catalog or other redirection mechanisms in place for retrieving XSDs, be sure to check those as well.