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>.\'
    

解决方法

        创建一个限制ѭ3that的新简单类型,并使用
<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