Schema Simple
# XSD Simple Elements
* * *
XML Schema can define elements in an XML document.
A simple element is an element that contains only text. It cannot contain any other elements or attributes.
* * *
## What Is a Simple Element?
A simple element is an element that contains only text. It cannot contain any other elements or attributes.
However, the restriction "contains only text" is easily misunderstood. Text comes in many types. It can be one of the built-in types defined by XML Schema (boolean, string, date, etc.), or it can be a custom type you define yourself.
You can also add restrictions (called facets) to data types to limit their content, or require the data to match a specific pattern.
* * *
## Defining Simple Elements
The syntax for defining a simple element is:
Here, xxx is the name of the element, and yyy is the data type of the element. XML Schema has many built-in data types.
### The most commonly used types are:
* xs:string
* xs:decimal
* xs:integer
* xs:boolean
* xs:date
* xs:time
### Example
These are some XML elements:
Refsnes
36
1970-03-27
Here are the corresponding simple element definitions:
* * *
## Default and Fixed Values for Simple Elements
Simple elements can have specified default or fixed values.
A default value is automatically assigned to the element when no other value is specified.
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":
YouTip