xml-схема, точность десятичного значения

#xsd

#xsd

Вопрос:

Это мой 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>.'
  

Ответ №1:

Создайте новый простой тип, который ограничивает 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

Комментарии:

1. Спасибо за помощь. Я добавляю <имя элемента =»rekVrednostDdv» type=»tns:decimalTwoPrec» nillable =»true»/> и теперь, я думаю, работает.