XML Schema validation error: Invalid content starting with

XML Schema validation error: Invalid content starting with

我有一个 XML 文档未通过 XML 架构验证,错误为:

Invalid content was found starting with element 'Signature'. One of '{WC["http://www.w3c.org/2000/09/xmldsig#"]}' is expected.

这是 XML 示例:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CMAC_Alert_Attributes xmlns="cmac:1.0">
    <CMAC_response_code>Monitor</CMAC_response_code>
    <CMAC_note />
    <CMAC_Digital_Signature>
        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SignedInfo>
                <CanonicalizationMethod
                    Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                <SignatureMethod
                    Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
                <Reference URI="">
                    <Transforms>
                        <Transform
                            Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                    </Transforms>
                    <DigestMethod
                        Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
                    <DigestValue>pdcsgn0sXaV1cvzpXaoG1nIxC/kDm2I6iFPI87u7s5c=
                    </DigestValue>
                </Reference>
            </SignedInfo>
            <SignatureValue>ZrpBOAWuttOIWgfhdfghdghf5rFUqMiqaBJps9w1AWlfPZIxrT9r/D7LByFZBAsXOPjREjPGM7gRANSRFlqaWX
                8z6e5WrlwaHsnbhML810DSaP2rbnoSM6saXyt+s3gj2KLJPn3TWT+UQ7lvmoe11uWL3Bs+frh/fs
                eyvLVlE0z0dfghS9JrioksKT8GrF7aglCLEEecfdghdfghdfghir2GSXFTvtGJ6oRaOYAZVj60JaeY/p5lqAP/qWh+BI
                tRz8LLYLwkfSUtlhiNTG46mciCwTDhZdfghdfghylG9O2FIUeGGQWMWUI223oHow+QsVRGUvHDsD36DOGN7d
                /Ywht8nftbWBSAUuTDqfJVKye8q+lw6f7VYPHg==
            </SignatureValue>

        </Signature>
    </CMAC_Digital_Signature>
</CMAC_Alert_Attributes>

这里是 XSD:

<?xml version = "1.0" encoding = "UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="cmac:1.0" xmlns:cmac="cmac:1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <element name="CMAC_Alert_Attributes">
    <complexType>
            <sequence>
                <element name="CMAC_response_code" type="string"
                    minOccurs="0" maxOccurs="unbounded" />
                <element name="CMAC_note" type="string" minOccurs="0"
                    maxOccurs="unbounded" />

                <element name="CMAC_Digital_Signature" minOccurs="0">
                    <complexType>
                        <sequence>
                            <any namespace="http://www.w3c.org/2000/09/xmldsig#"
                                processContents="lax" minOccurs="0" maxOccurs="unbounded" />
                        </sequence>
                    </complexType>
                </element>
            </sequence>
        </complexType>
    </element>
    <element name="valueName" type="string" />
    <element name="value" type="string" />
</schema>

目的是指定一个封装的签名。我尝试了很多替代方法,包括 includeelement ref=... 等,但都无济于事。

在你的XSD中,更改

<any namespace="http://www.w3c.org/2000/09/xmldsig#"
                             ^

<any namespace="http://www.w3.org/2000/09/xmldsig#"

并且您的 XML 将对您的 XSD 有效。