dictionary.xsd - A Sample XSD XML Schema File

This section provides a tutorial example of XSD XML Schema file, dictionary.xsd, using XSD statements: schema, element, attribute, simpleType, complexType, etc.

Let's revise my dictionary XML file with XSD link, dictionary_xsd.xml:

<?xml version="1.0"?>
<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="dictionary.xsd">
<!-- dictionary_xsd.xml
 - Copyright (c) 2002-2018 HerongYang.com. All Rights Reserved.
-->
 <word acronym="true">
  <name>XML</name>
  <definition reference="Herong's Notes">eXtensible Markup
Language.</definition>
  <update date="2014-12-23"/>
 </word>
 <word symbol="true">
  <name><</name>
  <definition>Mathematical symbol representing the "less than" logical
operation, like: 1<2.</definition>
  <definition>Reserved symbol in XML representing the beginning of
tags, like: <![CDATA[<p>Hello world!</p>]]>
  </definition>
 </word>
 <word symbol="false" acronym="false">
  <name>extensible</name>
  <definition>Capable of being extended.</definition>
 </word>
</dictionary>

And write an XSD XML Schema file, dictionary.xsd:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:element name="dictionary" type="dictionaryType"/>
 <xsd:complexType name="dictionaryType">
  <xsd:sequence>
   <xsd:element name="word" type="wordType" maxOccurs="unbounded"/>
  </xsd:sequence>
 </xsd:complexType>
 <xsd:complexType name="wordType">
  <xsd:sequence>
   <xsd:element name="name" type="xsd:string"/>
   <xsd:element name="definition" type="definitionType"
    maxOccurs="unbounded"/>
   <xsd:element name="update" type="updateType" minOccurs="0"/>
  </xsd:sequence>
  <xsd:attribute name="acronym" type="xsd:boolean" use="optional"/>
  <xsd:attribute name="symbol" type="xsd:boolean" use="optional"/>
 </xsd:complexType>
 <xsd:complexType name="definitionType" mixed="true">
  <xsd:attribute name="reference" type="xsd:string"/>
 </xsd:complexType>
 <xsd:complexType name="updateType">
  <xsd:attribute name="date">
   <xsd:simpleType>
    <xsd:restriction base="xsd:string">
     <xsd:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}"/>
    </xsd:restriction>
   </xsd:simpleType>
  </xsd:attribute>
 </xsd:complexType>
</xsd:schema>

Note that:

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 XML-JSON Document Conversion

 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

 Java Implementation of XSLT

 XSLT (XSL Transformations) Introduction

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 PHP Extensions for XML Manipulation

 Processing XML with Python Scripts

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML Plugin Packages for Atom Editor

 XML 1.1 Changes and Parsing Examples

 Archived Tutorials

 References

 Full Version in PDF/EPUB