XSD Tutorials - Herong's Tutorial Examples
∟XML Parser API - Xerces2 Java Parser
∟Testing Examples of XSD File and XML File
This section provides an example XML file assigned with an example XML Schema file (XSD).
In order to test my XML Schema validator using Xerces2, I wrote this example XSD file, dictionary.xsd:
<?xml version="1.0"?> <!-- dictionary.xsd - Copyright (c) 2013 by Dr. Herong Yang, herongyang.com --> <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>
Based on this XSD file, I wrote this invalid example XML file, dictionary_invalid_xsd.xml, with the XSD file assigned through the "xsi" attribute:
<?xml version="1.0"?> <dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="dictionary.xsd"> <!-- dictionary_invalid_xsd.xml - Copyright (c) 2013 by Dr. Herong Yang, herongyang.com --> <word acronym="yes"> <name>XML</name> <definition reference="Herong's Notes">eXtensible Markup Language.</definition> <update date="23-Dec-2003"/> </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> <update editor="Herong Yang"/> </word> <word symbol="no" acronym="false"> <name>extensible</name> <definition>Capable of being extended.</definition> </word> </dictionary>
Last update: 2013.
Table of Contents
About This Book
Introduction to XML Schema
XML Editor and Schema Processor - XMLPad
Java API for XML Processing - JAXP
JAXP - XML Schema (XSD) Validation
►XML Parser API - Xerces2 Java Parser
Installing Xerces2 Java Parser for XSD 1.1
►Testing Examples of XSD File and XML File
XML Schema (XSD) Validation using XMLReader
Running XMLReaderValidator with Xerces2 2.11.0 Beta
Running XMLReaderValidator on XSD 1.1 Schema
XML Schema (XSD) Validation using SAXParser
SAXParser for XSD Validation in JDK 1.7
SAXParser for XSD 1.1 Validation
Xsd11SchemaValidator.java for XSD 1.1 Validation
Xsd11SchemaValidator.java XSD 1.1 Test Result
XML Schema Language - Basics
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 Declaration
XML Schema Location and Namespace in XML Documents
Overriding Element Types in XML Documents
Linking Multiple Schema Documents Together
Glossary
References
PDF Printing Version