cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found

那年仲夏 提交于 2019-12-06 16:10:28
kjhughes

Two options...

Option One: If you do not want to have to have the definition of p:Reviewer present, add processContents="lax" to your xs:any element:

      <xs:any namespace="##any" minOccurs="0"  processContents="lax"/>

Per XML Schema Part 0: Primer Second Edition:

The lax value of the processContents attribute instructs an XML processor to validate the element content on a can-do basis: It will validate elements and attributes for which it can obtain schema information, but it will not signal errors for those it cannot obtain any schema information.

See also XML Validation in Java: processContents=“lax” seems not to work correctly.

You should also carefully adjust your xsi:schemaLocation values to point to the actual filename of each XSD for each namespace in play. Here is your XML instance with the changes that I made:

<?xml version="1.0" encoding="UTF-8"?>
<pr:BookCatalogue
    xmlns:pr="http://www.w3schools.com"
    xmlns:p="http://www.w3schools.com/1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3schools.com BookCatalogue.xsd http://www.w3schools.com/1 Reviewer.xsd">
    <pr:Book>
        <pr:Title>pr:Title</pr:Title>
        <pr:Author>pr:Author</pr:Author>
        <pr:Date>pr:Date</pr:Date>
        <pr:ISBN>pr:ISBN</pr:ISBN>
        <pr:Publisher>pr:Publisher</pr:Publisher>
        <p:Reviewer>
            <p:Name>
                <p:First>p:First</p:First>
                <p:Last>p:Last</p:Last>
            </p:Name>
        </p:Reviewer>
    </pr:Book>
</pr:BookCatalogue>

Note: Make sure that the targetNamespace in Review.xsd matches what's declared for it in BookCatalogue.xml's xsi:schemaLocation attribute.

Option Two: If you do want to insist that the definition of p:Reviewer be present, just make the above changes to be sure that Review.xsd can be found per the xsi:schemaLocation mechanism. No processContents setting is required; it defaults to strict.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!