Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XSD Simple Elements

XSD Simple Elements


XML Schema can define the elements of an XML document.

Simple elements are elements that contain only text. They do not contain any other elements or attributes.


What is a simple element?

Simple elements are elements that contain only text. They do not contain any other elements or attributes.

However, the restriction "text only" can easily be misleading. There are many types of text. It can be one of the types included in the XML Schema definition (Boolean, string, date, etc.), or it can be a custom type you define yourself.

You can also add restrictions (i.e., facets) to a data type to limit its content, or you can require the data to match a specific pattern.


Defining simple elements

The syntax for defining a simple element:

Here xxx refers to the name of the element, and yyy refers to the data type of the element. XML Schema has many built-in data types.

The most commonly used types are:

Example

Here are some XML elements:

Refsnes

36

1970-03-27

This is the corresponding simple element definition:


Default and fixed values of simple elements

A simple element can have a specified default or fixed value.

When no other value is specified, the default value is automatically assigned to the element.

In the following example, the default value is "red":

A fixed value is also automatically assigned to the element, and you cannot specify another value.

In the following example, the fixed value is "red":