XSD Tutorials - Herong's Tutorial Examples - v5.23, by Herong Yang
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) 2002-2013 HerongYang.com. 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.
Table of Contents
XML Editor and Schema Processor - XMLPad
Java API for XML Processing - JAXP
JAXP - XML Schema (XSD) Validation
Xerces2 Java Parser - Java API of XML Parsers
Introduction of XSD Built-in Datatypes
"string" and Its Derived Datatypes
"decimal" and Its Derived Datatypes
"dateTime" and Its Related Datatypes
Miscellaneous Built-in Datatypes
Facets, Constraining Facets and Restriction Datatypes
"simpleType" - Defining Your Own Simple Datatypes
Complex Element vs. Simple Element
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 & Text Content
Using Shorthand for "complexContent" with "restriction"
Identity-Constraints: unique, key and keyref
Assertion as Custom Validation Rules
XML Schema Location and Namespace in XML Documents
Overriding Element Types in XML Documents