2011-05-30 89 views
9

的精度這是我的XML(不是全部):XML模式,十進制值

<xsd:complexType name="xx"> 
    <xsd:complexContent> 
     <xsd:extension base="tns:xx"> 
     <xsd:sequence> 
      <xsd:element name="rekVrednostDdv" nillable="true" type="decimal"/> 
      <xsd:element name="xx" nillable="true" type="dateTime"/> 
      <xsd:element name="xx" nillable="true" type="decimal"/> 
      <xsd:element name="xx" nillable="true" type="string"/> 
      <xsd:element name="xx" nillable="true" type="dateTime"/> 
      <xsd:element name="xx" nillable="true" type="string"/> 
      <xsd:element name="xx" nillable="true" type="decimal"/> 
      <xsd:element name="xx" nillable="true" type="decimal"/> 
      <xsd:element name="xx" nillable="true" type="string"/> 
      <xsd:element name="xx" nillable="true" type="string"/> 
      <xsd:element name="xx" nillable="true" type="decimal"/> 
      <xsd:element name="xx" nillable="true" type="tns:xx"/> 
      <xsd:element name="xx" nillable="true" type="dateTime"/> 
      <xsd:element name="xx" nillable="true" type="string"/> 
      <xsd:element name="xx" nillable="true" type="string"/> 
      <xsd:element name="xx" nillable="true" type="string"/> 
     </xsd:sequence> 
     </xsd:extension> 
    </xsd:complexContent> 
    </xsd:complexType> 

例如rekVrednostDdv必須有精度2.如何判斷這種類型有精密2.

我嘗試這樣的:

<xsd:element name="rekVrednostDdv" nillable="true"> 
        <xsd:simpleType> 
         <xsd:restriction base="decimal"> 
          <xsd:precision value="6"/> 
          <xsd:scale value="2"/> 
         </xsd:restriction> 
        </xsd:simpleType> 
       </xsd:element> 

,但現在我得到使用http://www.brainbell.com/tutorials/XML/Working_With_Simple_Types.htm

Invalid XML schema: 'Element <xsd:precision> is not allowed under element <xsd:restriction>.' 

回答

15

創建一個新的簡單類型,限制xs:decimal並使用<xs:fractionDigits/>來定義精度。然後在你的元素定義中引用這個類型。

<xs:simpleType name="decimalTwoPrec"> 
    <xs:restriction base="xs:decimal"> 
     <xs:fractionDigits value="2" /> 
    </xs:restriction> 
</xs:simpleType> 

<xs:element name="rekVrednostDdv" nillable="true" type="decimalTwoPrec"/> 

欲瞭解更多信息,請參閱該規範http://www.w3.org/TR/xmlschema-2/#rf-fractionDigits

+0

THX的幫助。我添加現在我認爲可行。 – senzacionale 2011-05-30 11:51:54