XSD Simple Elements

We can use the XML Schemas to define the elements of the XML files. An XML element that contains only text is called a simple element. No other elements or attributes can be included in it.

What is a Simple Element?

An XML element that contains only text is called a simple element and no other elements or attributes can be included in it. The “only text” restriction of a simple element is misleading though. There are many different types of texts, such as the types included in the XML Schema definition (boolean, string, date, etc.), or a custom type. Also, to limit the contents of a data type, we can add restrictions (facets), or the data can be required to match a specific pattern.

Defining a Simple Element:

Syntax: Defining a simple element:


Here, the name of the element is represented by xxx and the data type of the element is represented by yyy.

XML Schema built-in data types:

The most common built-in data types of an XML Schema are:

  • xs:string
  • xs:decimal
  • xs:integer
  • xs:boolean
  • xs:date
  • xs:time

Example:

XML elements:

Tom
25
2000-09-21

Corresponding simple element definitions:




Default and Fixed Values for Simple Elements:

We can either specify a default value or a fixed value for a simple element. When no other value is specified, a default value is automatically assigned to the element.

Example:


Explanation: Here, the default value is “rose”. When a fixed value is assigned, we cannot specify another value. It is also automatically assigned to the element.

Example:


Explanation: Here, the fixed value is “rose”.

Please follow and like us:
Content Protection by DMCA.com