2017-10-10 169 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

回答