XSD Tutorials - Herong's Tutorial Examples

https://www.herongyang.com/XSD

Copyright © 2002-2024 Herong Yang. All rights reserved.

XSD Tutorials This book is a collection of tutorial examples and notes written by the author while he was learning XSD (XML Schema Definition). Topics include: XSD (XML Schema Definition) specification and processors; JAXP (Java API for XML Processing) API; XSD Schema XML DOM/SAX validators; Using Xerces2 Java Parser API; XSD Built-in Datatypes: string, normalizedString, token, integer, long, int, short, byte, gYear, gMonth, gDay, gYearMonth, gMonthDay, duration, yearMonthDuration, dayTimeDuration, atomic, list, union; simpleContent and complexType; unique, key and keyref identity constraints; assert and assertion validation rules; Schema Component Reuse - include, redefine or import. Updated in 2024 (Version v5.23) with minor changes.

Table of Contents

About This Book

Introduction to XML Schema

What Is XSD (XML Schema Definition)?

"Hello world!" Example of XSD

XML Schema Processors

XML Editor and Schema Processor - XMLPad

Installing WMHelp XMLPad Pro

Creating and Editing XML Documents

Creating and Editing XML Schema Documents

Assigning XML Schema to XML Documents

Validating XML Documents with Assigned XSD

Validating Non-Conforming XML Documents

XMLPad Crash When Validating Non-Conforming XML Documents

Generating XML Schema Diagrams

Generating XML Schema Documentations

Java API for XML Processing - JAXP

What Is JAXP?

Downloading and installing JDK

Compiling and Running Java Programs

XML File DOM Parser - XmlDomFileParser.java

JAXP API Module (java.xml.jmod) - Packages and Classes

JAXP - XML Schema (XSD) Validation

Standard Steps to Validate XML Documents Against a Schema

XSD Schema File Loader - XsdSchemaLoader.java

XSD Schema File Loading Errors

XSD Schema XML DOM Validator - XsdSchemaDomValidator.java

XSD Schema XML DOM Validation Errors

XSD Schema XML DOM Validator with Error Handler

XSD Schema XML SAX Validator - XsdSchemaSaxValidator.java

XSD Schema XML SAX Validation Errors

XSD Schema XML SAX Validator with Error Handler

XSD Schema XML Validator - Final Version

XSD 1.1 Not Supported in JDK 13

Xerces2 Java Parser - Java API of XML Parsers

Installing Xerces2 Java Parser for XSD 1.1

Verify Installation of Xerces2

Xerces2 Sample Program List

Xerces2 Sample Program dom.Counter

dom.Counter Validating XML with Associated XSD

dom.GetElementsByTagName and dom.Writer

sax.DocumentTracer and sax.Writer

Examples of XSD and XML Files with Errors

sax.Writer Reporting Errors Embedded in XML Structure

XSD 1.1 not Supported by sax.Writer

XSD 1.1 Supported by jaxp.SourceValidator

Examples of XSD 1.1 and XML Files with Errors

jaxp.TypeInfoWriter as an XSD 1.1 Validation Tool

Using Xerces2 Java APIs

JAXP, DOM and SAX APIs in Xerces2 JARs

XML Schema (XSD) Validation using XMLReader

Running XMLReaderValidator on XSD 1.1 Schema

XML Schema (XSD) Validation using SAXParser

SAXParser for XSD Validation Fixed

SAXParser for XSD 1.1 Validation

Xsd11SchemaValidator.java for XSD 1.1 Validation

Xsd11SchemaValidator.java XSD 1.1 Test Result

XML Schema Language - Basics

Schema and Schema XML Representation

Checking Schema Documents - XsdSchemaChecker.java

Creating Schema Documents - "schema" Element

Declaring Root Elements - "element" Element

Specifying Element Datatype - "type" Attribute

Using XML Schema Built-in Datatypes

Using XML Schema Built-in Datatypes Incorrectly

Validating XML Documents against Schema Documents

Deriving New Simple Datatypes - "simpleType" Element

Defining Complex Datatypes - "complexType" Element

Validation Error Examples on Complex Datatypes

Introduction of XSD Built-in Datatypes

Overview of XSD 1.1 Built-in Datatypes

List of Built-in Datatypes

Datatypes, Values and Representations

Datatypes, Values and Representations - Example

Built-in Datatypes Lexical Representation Examples

Declaring Elements and Attributes with Built-in Datatypes

Defining New Datatypes with Built-in Datatypes

"anyType" Built-in Datatype Values and Representations

"anySimpleType" Built-in Datatype Values and Representations

"anyAtomicType" Built-in Datatype Values and Representations

"string" and Its Derived Datatypes

"string" Datatype Values and Representations

"normalizedString" Datatype Values and Representations

"token" Datatype Values and Representations

"language" Datatype Values and Representations

"language" Datatype Values - Invalid Inputs

"Name" Datatype Values and Representations

"NMTOKEN" Datatype Values and Representations

"NCName" Datatype Values and Representations

"ENTITY" Datatype Values and Representations

"ID" Datatype Values and Representations

"IDREF" Datatype Values and Representations

"decimal" and Its Derived Datatypes

"decimal" Datatype Values and Representations

"integer" Datatype Values and Representations

"long", "int", "short" and "byte" Datatypes

"nonNegativeInteger", "positiveInteger", "nonPositiveInteger", "negativeInteger" Datatypes

""unsignedLong" and "unsignedShort" Datatypes

"dateTime" and Its Related Datatypes

Date/Time Seven-Property Model

"dateTime" Datatype Values and Representations

"dateTimeStamp" Datatype Values and Representations

"date" Datatype Values and Representations

"time" Datatype Values and Representations

"gYear", "gMonth" and "gDay" Datatypes

"gYearMonth" and "gMonthDay" Datatypes

"duration" Datatype Values and Representations

"yearMonthDuration" Datatype Values and Representations

"dayTimeDuration" Datatype Values and Representations

Date, Time and Duration Datatype Summary

Miscellaneous Built-in Datatypes

"anyURI" Datatype Values and Representations

"QName" Datatype Values and Representations

"NOTATION" Datatype Values and Representations

"base64Binary" Datatype Values and Representations

"hexBinary" Datatype Values and Representations

"float" and "double" Datatype Values and Representations

"boolean" Datatype Values and Representations

Facets, Constraining Facets and Restriction Datatypes

"simpleType" - Defining Your Own Simple Datatypes

What Is Simple Datatype?

"simpleType" Components - User-Defined Simple Datatypes

"simpleType" Components with "restriction" Child Components

"simpleType" Components with "union" Child Components

"simpleType" Components with "list" Child Components

Atomic, List, Atomic Union and List Union Datatypes

Constraining Facets on List Datatypes

Constraining Facets on Union Datatypes

Nested List Datatypes - Not Allowed

Nested Atomic and List Union Datatypes

Complex Element Declaration

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 & Text Content

Using Shorthand for "complexContent" with "restriction"

Identity-Constraints: unique, key and keyref

What Are Identity-Constraints?

What Is "unique" Identity-Constraint?

What Is "key" Identity-Constraint?

What Is "keyref" Identity-Constraint?

"keyref" Identity-Constraint XSD Example

Identity-Constraint with Multiple Fields

Assertion as Custom Validation Rules

XML Schema Location and Namespace in XML Documents

Assigning XML Schema Location in XML Documents

Validating XML Documents with Schema Locations

Validating XML Documents with Schema Locations - JAXP

Assigning XML Schema Location with Namespaces

Testing XML Schema Location with Namespaces

Testing XML Schema Location with Namespaces - JAXP

Overriding Element Types in XML Documents

Linking Multiple Schema Documents Together

Schema Component Reuse - "include", "redefine" or "import"

Including Old Schema Documents - "include" Component

Including Old Schema Documents - Examples

Including Old Schema Documents - Errors

Redefining Old Datatypes - "redefine" Component

Redefining Old Datatypes - XML Examples

Redefining Old Datatypes - Errors

Importing Declarations Across Namespaces - "import" Component

Importing Declarations Across Namespaces - Examples

Using Elements Declared in Different Namespaces

Using Elements Declared in Different Namespaces - Errors

Glossary

Archived Tutorials

Archived: Xerces2 Java 2.11.0 XML Schema 1.1 Beta

Archived: Running XMLReaderValidator with Xerces2 2.11.0 Beta

Archived: Downloading and installing Java SE 1.6 Update 2

References

Full Version in PDF/EPUB

Keywords: XSD, XML, Schema, Validation, W3C, Tutorial, Example