ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 8 / 8 << | Prev | Next |
Contents > Definition of own types > The number must not be in scientific notation

The number must not be in scientific notation

  1. XML Schema
  2. Relax NG
XML Schema keys: decimal

1. XML Schema

The element "A" represents a number (decimal), which must not be in the scientific format (e.g. 1.5E+10 is forbidden - such numbers are not processed by XSLT, for example). We will just use the datatype "decimal", not "float" or "double" (the two latter allow mantissa-exponent notation).

Valid document


<A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >999.99</A>

Valid document


<A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >-0.50</A>

Invalid document
Scientific notation is not allowed for decimals.


<A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >1.5e+10</A>

Invalid document
NaN is not allowed too.


<A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >NaN</A>

Invalid document
INF/-INF is not allowed too.


<A xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >-INF</A>

Correct XML Schema (correct_0.xsd)


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

  <xsd:element name="A" type="xsd:decimal"/>
</xsd:schema>

2. Relax NG

We will use the "decimal" datatype from XML Schemas. The element "A" must contain this pattern.

Valid document


<A xmlns="">999.99</A>

Valid document


<A xmlns="">-0.50</A>

Invalid document
Scientific notation is not allowed for decimals.


<A xmlns="">1.5e+10</A>

Invalid document
NaN is not allowed too.


<A xmlns="">NaN</A>

Invalid document
INF/-INF is not allowed too.


<A xmlns="">-INF</A>

Correct Relax NG schema (correctRelax_0.rng)


<grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" xmlns="http://relaxng.org/ns/structure/1.0" >

  <start>
    <element>
      <name ns="">A</name>
      <data type="decimal"/>
    </element>
  </start>
</grammar>