【发布时间】:2020-02-08 13:48:05
【问题描述】:
我想根据 XSD 架构验证签名的 XML 文件。问题是签名 XML 元素包含命名空间属性,并且 XSD 架构无法识别命名空间。所以我在验证过程中总是遇到这个错误:
<"org.xml.sax.SAXParseException; lineNumber: 2867; columnNumber: 55; cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.w3.org/2000/09/xmldsig#":Signature}'. One of '{Signature}' is expected.
这是我要解析的 xml 的 XML 部分:
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"/>
<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>HNSlwP/h00NyO01CLexn+gbYxahOgjFfUKGJG3ggSMU=</DigestValue>
</Reference>
</SignedInfo><SignatureValue>EaLbG4wvdELbRw1uIou01WlJAX+J233aTUZI5c0yELkIjfBeV+XNbQ==</SignatureValue>
<KeyInfo>
<KeyValue>
<DSAKeyValue><P>/KaCzo4Syrom78z3EQ5SbbB4sF7ey80etKII864WF64B81uRpH5t9jQTxeEu0ImbzRMqzVDZkVG9
xD7nN1kuFw==</P>
<Q>li7dzDacuo67Jg7mtqEm2TRuOMU=</Q><G>Z4Rxsnqc9E7pGknFFH2xqaryRPBaQ01khpMdLRQnG541Awtx/XPaF5Bpsy4pNWMOHCBiNU0Nogps
QW5QvnlMpA==</G>
<Y>7c2FbHxE5zTY6PkKQfHDdgGySWNSKYQ+j9nnD6FjwialpVuy6AKAbV8kdOYD3MMOMTJD8+N0+ZO9
Ofx6Nh6UIw==</Y>
</DSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
在这里使用以下标记在我的 XML 中声明位置:
<xs:element ref="Signature"/>
这里是我对签名元素的定义:
<xs:element name="Signature" type="SignatureType"/>
<xs:complexType name="SignatureType">
<xs:sequence>
<xs:any namespace="http://www.w3.org/2000/09/xmldsig#"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="SignedInfo"/>
<xs:element ref="SignatureValue"/>
<xs:element ref="KeyInfo" minOccurs="0"/>
<xs:element ref="Object" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Id" type="xs:ID"/>
</xs:complexType>```
【问题讨论】:
标签: xml xsd namespaces signature