i-Lab Guide To: XML Schema

What Is It ?

XML Schema are a successor to the DTD (Document Type Definition) for defining the structure and content of XML data. XML Schema present a number of advantages over DTDs :-

  • they are themselves valid XML files (i.e. they can be translated using XSLT for example to provide documentation or sample data)
  • they provide many more facilities for data validation

The main disadvantage of XML schema is that they are much more verbose than DTDs, making tool-support obligatory for all but the simplest of definitions.

   
Namespace  
xmlns:xs http://www.w3.org/2001/XMLSchema
Data Types  
boolean
0, 1, true, false
date CCYY-MM-DD
time hh:mm:ss
dateTime CCYY-MM-DDThh:mm:ss (ISO 8601)
float, double  
decimal, integer... long, int, short & byte
   
base64binary 65 characters { Alphanumerics, equals, plus and forward slash } plus whitespace
hexBinary 16 characters { Numbers and upper-case letters } plus whitespace
string Free text except that special characters need to be escaped
normalisedString As string, except without line feeds, carriage returns or tabs
token As normalisedString, except without leading/trailing, or groups of more than one, spaces

NMTOKEN

Alphanumerics plus period, colon, underscore and hyphen (no spaces)
NMTOKENS One or NMTOKENs separated by single spaces
Name As nmtoken, except must start with a letter, underscore or colon
NCName As Name except without colons

Commenting

 
XML 1.0 Comments
<!-- Read by parser but lost with XSLT -->
xs:annotation elements with xs:documentation and/or xs:appinfo children
Foreign Attributes
TBD
Character classes  
[a-z] Characters between a and z
[^a-z] Characters not between a and z
\d Digits
\D Non digits
\w Word characters
\W Non word characters
Quantifiers  
{n,m} between n and m
{n} exactly n
* 0 or more
+ 1 or more
? 0 or 1 {0,1}
   

© 2003 i-Lab Limited