ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index
Contents > Definition of own types

Definition of own types

Definition of a custom simpleType - temperature must be greater than -273.15

The element "T" must contain number greater than -273.15. We will define our custom type for temperature named "Temperature" and will require the element "T" to be of that type.

The element "T" must contain number greater than -273.15. We will define a custom pattern named "Temperature" and use it for the definition of the element "T".

...
Limiting string length

The element "A" must contain a string which is exactly three characters long. We will define our custom type for the string named "myString" and will require the element "A" to be of that type.

The element "A" must contain a string which is exactly three characters long. We will define our custom pattern - a string exactly three characters long - and the element "A" must contain this pattern.

...
Limiting the number of decimal places

The element "A" represents your salary - it must be positive number and it must be rounded to two decimal places. We will define our custom type "Salary" using "minExclusive" and "fractionDigits" elements. The element "A" must be of that type.

The element "A" must be positive number and it must be rounded to two decimal places. We will use the "decimal" datatype from XML Schemas and restrict it using the "fractionDigits" and "minExclusive" parameters (facets).

...
Limiting both the number of decimal places and total places

The element "A" represents a number in the format xxx.xx or -xxx.xx. It must have max. two decimal places and must have 5 total digits. We will define our custom type "myNumber" using "totalDigits" and "fractionDigits" elements. The element "A" must be of that type.

The element "A" represents a number in the format xxx.xx or -xxx.xx. It must it must have two decimal places and must have 5 total digits. We will use the "decimal" datatype from XML Schemas and restrict it using using "totalDigits" and "fractionDigits". The element "A" must contain this pattern.

...
String must contain e-mail address

The element "A" must contain an email address. We will define our custom type, which will at least approximately check the validity of the address. We will use the "pattern" element, to restrict the string using regular expressions.

The element "A" must contain a string representing an e-mail address.

...
Element contains date

The element "A" must contain a date, which is not less than 1.1.2001. We will define our custom type for the string named "myDate" and will require the element "A" to be of that type.

We will use the "date" datatype from XML Schemas and restrict it using using "minInclusive". The element "A" must contain this pattern.

...
Element represents time duration

The element "A" must represents time duration, which is from one day to one week. We will define our custom type named "myDuration" and will require the element "A" to be of that type.

...
The number must not be in scientific notation

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

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

...