Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Xsd Numeric in XML

Xsd Numeric in XML

? XSD Numeric Types in XML Schema

In XSD (XML Schema Definition), there are several built-in numeric data types you can use to define elements or attributes that must hold numbers. These help validate that the data is numeric and can also enforce constraints like minimum and maximum values.


? Common Numeric Types in XSD

XSD TypeDescriptionExample Value
xs:integerAny integer (positive, negative, zero)42, -7
xs:decimalDecimal number (floating point)3.14, 100.00
xs:float32-bit floating point1.23E4
xs:double64-bit floating point2.718281828
xs:nonNegativeIntegerInteger ? 00, 25
xs:positiveIntegerInteger > 01, 99
xs:nonPositiveIntegerInteger ? 00, -5
xs:negativeIntegerInteger < 0-1, -20

? Example: Using Numeric Types in XSD

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">  <xs:element name="product">    <xs:complexType>      <xs:sequence>        <xs:element name="id" type="xs:integer"/>        <xs:element name="price" type="xs:decimal"/>        <xs:element name="quantity" type="xs:nonNegativeInteger"/>      </xs:sequence>    </xs:complexType>  </xs:element></xs:schema>

? Example XML Valid for Above XSD

<product>  <id>1001</id>  <price>19.99</price>  <quantity>5</quantity></product>

? Adding Numeric Restrictions (Min/Max)

You can restrict numeric ranges like this:

<xs:simpleType name="AgeType">  <xs:restriction base="xs:integer">    <xs:minInclusive value="0"/>    <xs:maxInclusive value="120"/>  </xs:restriction></xs:simpleType><xs:element name="age" type="AgeType"/>

This limits age to between 0 and 120 inclusive.


Summary

  • Use xs:integer or xs:decimal for general numbers.

  • Use derived types like xs:nonNegativeInteger to restrict the range.

  • Use restrictions to set min/max values.

  • Numeric types enable strong validation in your XML documents.


Want me to help create a full XML + XSD example demonstrating numeric types and restrictions?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql