XML Schema Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.00

Declaring Simple Elements

This section describes a tutorial example on how to declare a simple element that accepts only text content using a built-in datatype or a user defined simpleType datatype.

What is a simple element? A simple element is an XML element that does not have any attributes or any sub (child) elements. A simple element can be declared with a simple datatype.

In other word, a simple element is an element with text content, no sub (child) element, and no attribute. This type of element can be declared with a built-in datatype or a "simleType" derived from a built-in datatype.

Here is a sample schema, simple_element.xsd, that declares a simple element using "simpleType":

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!--simple_element.xsd
 - Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
-->

 <xs:element name="title">
 <xs:simpleType>
  <xs:restriction base="xs:string">
  <xs:length value="256"/>
  </xs:restriction>
 </xs:simpleType>
 </xs:element>

</xs:schema>

For more tutorial examples, see the built-in datatype chapter in this book.

Sections in This Chapter

Complex Element vs. Simple Element

Declaring Empty Elements

Declaring Simple Elements

Declaring Complex Elements with Simple Content

Declaring Complex Elements with Attributes Only

Declaring Complex Elements with Sub Elements Only

Declaring Complex Elements with Attributes and Sub Elements

Declaring Complex Elements with Attributes, Sub Elements and Text Content

Using Shorthand for "complexContent" with "restriction"

Dr. Herong Yang, updated in 2007
Declaring Simple Elements