Simple Element Types with Extended Data Types

This section describes simple element types using data types extended from XML Schema built-in data types. Data types can be extended with restrictions, union or list operations.

Simple XML Element Type: An XML element that has no child elements and no attributes. Simple XML elements can be defined by using XSD built-in data types. They can also be defined by using extended data types, which are defined by "simpleType" statements:

<xsd:simpleType name="my_type_name">
 <xsd:restriction base="xsd:type_name">
  XSD facet statements
 </xsd:restriction>
</xsd:simpleType>
<xsd:element name="element_name" type="my_type_name"/>

where "element_name" is the name of the XML element, "xsd:type_name" is a pre-defined data type serving as the base data type, and "my_type_name" is the new data type extended from the base data type.

Optional facet statements can be enclosed in the "restriction" statement to provide additional restrictions to the extended data type:

The syntax of facet statement is:

<xsd:facet_name value="facet_value">

Besides restricting the base data types to extend new data types, we can also extend new data types by define "union" or "list" of base data types.

Union: A collection of base data types. A value is valid for a union data type if and only it is valid for one of the base data types.

<xsd:simpleType name="my_type_name">
 <union>
  <xsd:restriction base="xsd:type_name_1">
   XSD facet statements
  </xsd:restriction>
  <xsd:restriction base="xsd:type_name_2">
   XSD facet statements
  </xsd:restriction>
 </union>
</xsd:simpleType>
<xsd:element name="element_name" type="my_type_name"/>

List: A data type for lists of values of a base data type. The list of values must be white space delimited. For example, the following code

<xsd:simpleType name="integerList">
 <list>
  <xsd:restriction base="xsd:integer">
   <xsd:minInclusive value="1">
   <xsd:maxInclusive value="49">
  </xsd:restriction>
 </list>
</xsd:simpleType>
<xsd:element name="winning_numbers" type="integerList"/>

defines that "winning_numbers" element is allowed to have a list of number in the range of 1 and 49.

Last update: 2014.

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 DOM (Document Object Model) Programming Interface

 SAX (Simple API for XML) Programming Interface

 DTD (Document Type Definition) Introduction

 Syntaxes of DTD Statements

 Validating an XML Document against the Specified DTD Document Type

 XSD (XML Schema Definition) Introduction

Syntaxes of XSD Statements

 "schema" - The Schema Declaration Statement

 "element" - The Element Declaration Statement

 Simple Element Types with Built-in Data Types

Simple Element Types with Extended Data Types

 Complex Element Types

 Simple Content Element Types

 Empty Element Types

 Anonymous or Inline Data Types

 dictionary.xsd - A Sample XSD XML Schema File

 Validating XML Documents Against Specified XML Schemas

 XSL (Extensible Stylesheet Language) Introduction

 XSLT (XSL Transformations) Introduction

 Java Implementation of XSLT

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML 1.1 Changes and Parsing Examples

 Outdated Tutorials

 References

 PDF Printing Version