2017-10-10 170 views
0

我们的一个XML将来会有一个签名块。如何将签名元素定义添加到XSD

我不知道把它的定义放到XSD文件中的位置。

我试图把下面末(关闭<xs:schem>前):在架构标签

<element name="Signature" type="ds:SignatureType"/> 
<complexType name="SignatureType"> 
    <sequence> 
     <element ref="ds:SignedInfo"/> 
     <element ref="ds:SignatureValue"/> 
    </sequence> 
    <attribute name="Id" type="ID" use="optional"/> 
</complexType> 

<element name="SignatureValue" type="ds:SignatureValueType"/> 
<complexType name="SignatureValueType"> 
    <simpleContent> 
     <extension base="base64Binary"> 
      <attribute name="Id" type="ID" use="optional"/> 
     </extension> 
    </simpleContent> 
</complexType> 

<element name="SignedInfo" type="ds:SignedInfoType"/> 
<complexType name="SignedInfoType"> 
    <sequence> 
     <element ref="ds:CanonicalizationMethod"/> 
     <element ref="ds:SignatureMethod"/> 
     <element ref="ds:Reference" maxOccurs="unbounded"/> 
    </sequence> 
    <attribute name="Id" type="ID" use="optional"/> 
</complexType> 

<element name="CanonicalizationMethod" type="ds:CanonicalizationMethodType"/> 
<complexType name="CanonicalizationMethodType" mixed="true"> 
    <sequence> 
     <any namespace="##any" minOccurs="0" maxOccurs="unbounded"/> 
     <!-- (0,unbounded) elements from (1,1) namespace --> 
    </sequence> 
    <attribute name="Algorithm" type="anyURI" use="required"/> 
</complexType> 

<element name="SignatureMethod" type="ds:SignatureMethodType"/> 
<complexType name="SignatureMethodType" mixed="true"> 
    <sequence> 
     <element name="HMACOutputLength" minOccurs="0" 
      type="ds:HMACOutputLengthType"/> 
      <any namespace="##other" minOccurs="0" maxOccurs="unbounded"/> 
     <!-- (0,unbounded) elements from (1,1) external namespace --> 
     </sequence> 
    <attribute name="Algorithm" type="anyURI" use="required"/> 
</complexType> 

<element name="Reference" type="ds:ReferenceType"/> 
<complexType name="ReferenceType"> 
    <sequence> 
     <element ref="ds:Transforms" minOccurs="0"/> 
     <element ref="ds:DigestMethod"/> 
     <element ref="ds:DigestValue"/> 
    </sequence> 
    <attribute name="Id" type="ID" use="optional"/> 
    <attribute name="URI" type="anyURI" use="optional"/> 
    <attribute name="Type" type="anyURI" use="optional"/> 
</complexType> 

<element name="Transforms" type="ds:TransformsType"/> 
<complexType name="TransformsType"> 
    <sequence> 
     <element ref="ds:Transform" maxOccurs="unbounded"/> 
    </sequence> 
</complexType> 

<element name="Transform" type="ds:TransformType"/> 
<complexType name="TransformType" mixed="true"> 
    <choice minOccurs="0" maxOccurs="unbounded"> 
     <any namespace="##other" processContents="lax"/> 
     <!-- (1,1) elements from (0,unbounded) namespaces --> 
     <element name="XPath" type="string"/> 
    </choice> 
    <attribute name="Algorithm" type="anyURI" use="required"/> 
</complexType> 

<element name="DigestMethod" type="ds:DigestMethodType"/> 
<complexType name="DigestMethodType" mixed="true"> 
    <sequence> 
     <any namespace="##other" processContents="lax" 
      minOccurs="0" maxOccurs="unbounded"/> 
    </sequence>  
    <attribute name="Algorithm" type="anyURI" use="required"/> 
</complexType> 

<element name="DigestValue" type="ds:DigestValueType"/> 
    <simpleType name="DigestValueType"> 
    <restriction base="base64Binary"/> 
</simpleType> 

我有以下几点:

<xs:schema xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 

W3C的检查告诉我有命名空间的一些问题。但我在这里丢失了,由于我缺乏对XSD知识

在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#rsa-sha1" /> 
    <Reference URI=""> 
    <Transforms> 
     <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> 
    </Transforms> 
    <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
    <DigestValue>[the digest value]</DigestValue> 
    </Reference> 
</SignedInfo> 
<SignatureValue>[the generated signature]</SignatureValue> 
</Signature> 

做什么样的变化我要补充到我的XSD,以便具有签名块的XML在XSD上验证为真?

+1

你可能有更多的成功,如果你花几个小时阅读XSD一些介绍教程粘贴整个定义。您显示的名称空间声明与您显示的模式片段中的名称空间用法不匹配,这表明您可能还需要阅读关于XML名称空间的一些教程以及它们的工作方式。祝你好运! –

+0

谢谢!对命名空间有一个基本的了解,我可以创建一个有效的XSD(请参阅下面的答案) – Woncker

回答