Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xml schema, precision of decimal value

Tags:

xsd

This is my xml (not whole):

<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>

For example rekVrednostDdv must have precision 2. How can i tell this type to have precision 2.

i try like this:

<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>

but now i get when using http://www.brainbell.com/tutorials/XML/Working_With_Simple_Types.htm

Invalid XML schema: 'Element <xsd:precision> is not allowed under element <xsd:restriction>.'
like image 206
senzacionale Avatar asked May 30 '11 11:05

senzacionale


People also ask

What is a decimal in XML?

Description. xs:decimal is the datatype that represents the set of all the decimal numbers with arbitrary lengths. Its lexical space allows any number of insignificant leading and trailing zeros (after the decimal point).

What is float in XML?

Description. The value space of xs:float is “float” (32 bits) floating-point numbers as defined by the IEEE. The lexical space uses a decimal format with optional scientific notation. The match between lexical (powers of 10) and value (powers of 2) spaces is approximate and is done on the closest value.

What is the difference between Xs int and XS integer?

The difference is the following: xs:int is a signed 32-bit integer. xs:integer is an integer unbounded value.

How do I set default value in XML?

You can specify the default value of an XML element or XML attribute by applying a DefaultValueAttribute to a member. To examine the result of applying the value, compile the application into a DLL or executable, and pass the resulting file as an argument to the XML Schema Definition tool (XSD.exe).


1 Answers

Create a new simple type that restricts xs:decimal and use <xs:fractionDigits/> to define the precision. Then refer to this type in your element definition.

<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"/>

For more info, see the spec http://www.w3.org/TR/xmlschema-2/#rf-fractionDigits

like image 150
jasso Avatar answered Sep 24 '22 18:09

jasso