What Are Identity-Constraints?

This section describes 3 types of identity constraints supported by XSD: 'unique', 'key' and 'keyref' identity constraints. They are very similar to concepts of UNIQUE, PRIMARY KEY and FOREIGN KEY constraints on multiple columns in a database table.

XSD offers 3 types of identity constraints:

1. "unique" Identity Constraint - A repeating set of attributes or elements are specified as a unique identity. Their values must be unique, if exist. "unique" identity constraint is very similar to the concept of UNIQUE constraint on multiple columns in a database table.

2. "key" Identity Constraint - A repeating set of attributes or elements are specified as a key identity. Their values must exist and be unique. "key" identity constraint is very similar to the concept of PRIMARY KEY constraint on multiple columns in a database table.

3. "keyref" Identity Constraint - A repeating set of attributes or elements are specified as a key reference identity. Their values must exist and refer to existing values another key identity. "keyref" identity constraint is very similar to the concept of FOREIGN KEY constraint on multiple columns in a database table.

A good example of a "unique" identity constraint is the "id" attribute used in XHTML documents. It should have unique values within the document, if used.

Last update: 2014.

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

 Xerces2 Java Parser - Java API of XML Parsers

 Using Xerces2 Java API

 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

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

 Overriding Element Types in XML Documents

 Linking Multiple Schema Documents Together

 Glossary

 References

 PDF Printing Version