D A T Y P I C
Definitive XML Schema

Definitive XML Schema

Priscilla Walmsley (pwalmsley@datypic.com)
1st edition (December 7, 2001)
Prentice Hall PTR; ISBN: 0130655678
Amazon.com
Buy at 37% off list price


Table of Contents

Chapter 1: Schemas: An introduction 2
1.1 What is an XML schema? 3
1.2 The purpose of schemas 4
1.2.1 Data validation 4
1.2.2 A contract with trading partners 5
1.2.3 System documentation 5
1.2.4 Augmentation of data 5
1.2.5 Application information 5
1.3 Schema design 6
1.3.1 Accuracy and precision 7
1.3.2 Clarity 7
1.3.3 Broad applicability 7
1.4 Schema languages 8
1.4.1 Document Type Definitions (DTDs) 8
1.4.2 Enter schemas 9
1.4.3 W3C XML Schema 9
1.4.4 Notes on terminology 10
1.4.4.1 Schema 10
1.4.4.2 Type 11
1.4.5 Additional schema languages 11
1.4.5.1 RELAX NG 11
1.4.5.2 Schematron 13
Chapter 2: A quick tour of XML Schema 16
2.1 An example schema 17
2.2 The components of XML Schema 18
2.2.1 Declarations vs. definitions 18
2.2.2 Global vs. local components 19
2.3 Elements and attributes 20
2.3.1 The tag/type distinction 20
2.4 Data types 21
2.4.1 Simple vs. complex types 21
2.4.2 Named vs. anonymous types 22
2.4.3 The type definition hierarchy 22
2.5 Simple types 23
2.5.1 Built-in simple types 23
2.5.2 Restricting simple types 24
2.5.3 List and union types 24
2.6 Complex types 25
2.6.1 Content types 25
2.6.2 Content models 26
2.6.3 Deriving complex types 27
2.7 Namespaces and XML Schema 28
2.8 Schema composition 30
2.9 Instances and schemas 30
2.10 Annotations 32
2.11 Advanced features 32
2.11.1 Reusable groups 33
2.11.2 Identity constraints 33
2.11.3 Substitution groups 33
2.11.4 Redefinition 33
Chapter 3: Namespaces 36
3.1 Namespaces in XML 37
3.1.1 Namespace names are URIs 38
3.1.2 Namespace declarations and prefixes 39
3.1.3 Default namespace declarations 41
3.1.4 Name terminology 42
3.1.5 Scope of namespace declarations 43
3.1.6 Overriding namespace declarations 43
3.1.7 Attributes and namespaces 45
3.1.8 A summary example 46
3.2 The relationship between namespaces and schemas 47
3.3 Using namespaces in XSDL 49
3.3.1 Target namespaces 49
3.3.2 The XML Schema Namespace 50
3.3.3 The XML Schema Instance Namespace 51
3.3.4 Namespace declarations in schema documents 51
3.3.4.1 Map a prefix to the XML Schema Namespace 51
3.3.4.2 Map a prefix to the target namespace 53
3.3.4.3 Map a prefix to all namespaces 53
Chapter 4: Schema composition 56
4.1 Modularizing schema documents 57
4.2 Defining schema documents 59
4.2.1 Defining a schema document in XSDL 59
4.3 Schema assembly 60
4.3.1 Assembling schemas from multiple documents 60
4.3.2 Uniqueness of qualified names 62
4.3.3 Missing components 63
4.3.4 Schema document defaults 64
4.4 include, redefine, and import 65
4.4.1 include 65
4.4.2 redefine 69
4.4.3 import 70
Chapter 5: Instances and schemas 74
5.1 Using the instance attributes 75
5.2 Schema processing 77
5.2.1 Validation 77
5.2.2 Augmenting the instance 78
5.3 Relating instances to schemas 79
5.4 Using XSDL hints in the instance 80
5.4.1 The xsi:schemaLocation attribute 80
5.4.2 The xsi:noNamespaceSchemaLocation attribute 82
5.5 Dereferencing namespaces 83
5.6 The root element 84
5.7 Using DTDs and schemas together 87
5.8 Using specific schema processors 88
5.8.1 XSV 89
5.8.2 Xerces 90
5.8.3 Oracle XDK 92
5.8.4 Microsoft MSXML 93
Chapter 6: Schema documentation and extension 96
6.1 The mechanics 97
6.1.1 Annotations 97
6.1.2 User documentation 98
6.1.3 Application information 100
6.1.4 Validating annotations 101
6.1.5 Non-native attributes 103
6.1.6 Design hint: Should I use annotations or non-native attributes? 104
6.2 User documentation 104
6.2.1 Types of user documentation 104
6.2.2 Data element definitions 105
6.2.3 Code documentation 106
6.2.4 Section comments 106
6.3 Application information 108
6.3.1 Types of application information 108
6.3.2 Schematron for co-occurrence constraints 108
6.3.3 Schema adjunct framework for RDBMS mappings 111
6.4 Notations 111
6.4.1 Declaring a notation 113
6.4.2 Declaring a notation attribute 113
6.4.3 Notations and unparsed entities 116
Chapter 7: Element declarations 118
7.1 Global and local element declarations 119
7.1.1 Global element declarations 119
7.1.2 Local element declarations 123
7.1.3 Design hint: Should I use global or local element declarations? 125
7.2 Declaring the data types of elements 126
7.3 Default and fixed values 128
7.3.1 Default values 129
7.3.2 Fixed values 131
7.4 Nils and nillability 132
7.4.1 Using xsi:nil in an instance 136
7.4.2 Making elements nillable 136
7.5 Qualified vs. unqualified forms 137
Chapter 8: Attribute declarations 140
8.1 Global and local attribute declarations 141
8.1.1 Design hint: Should I use attributes or elements? 142
8.1.2 Global attribute declarations 143
8.1.3 Local attribute declarations 145
8.1.4 Design hint: Should I declare attributes globally or locally? 147
8.2 Assigning types to attributes 148
8.3 Default and fixed values 149
8.3.1 Default values 150
8.3.2 Fixed values 151
8.4 Qualified vs. unqualified forms 152
Chapter 9: Simple types 154
9.1 Simple type varieties 155
9.1.1 Design hint: How much should I break down my data values? 156
9.2 Simple type definitions 157
9.2.1 Named simple types 157
9.2.2 Anonymous simple types 158
9.2.3 Design hint: Should I use named or anonymous types? 159
9.3 Simple type restrictions 161
9.3.1 Defining a restriction 162
9.3.2 Overview of the facets 163
9.3.3 Inheriting and restricting facets 164
9.3.4 Fixed facets 166
9.3.4.1 Design hint: When should I fix a facet? 167
9.4 Facets 168
9.4.1 Bounds facets 168
9.4.2 Length facets 169
9.4.2.1 Design hint: What if I want to allow empty values? 169
9.4.2.2 Design hint: What if I want to restrict the length of an integer? 170
9.4.3 totalDigits and fractionDigits 171
9.4.4 Enumeration 171
9.4.5 Pattern 173
9.4.6 Whitespace 176
9.5 Preventing simple type derivation 177
Chapter 10: Regular expressions 180
10.1 The structure of a regular expression 181
10.2 Atoms 183
10.2.1 Normal characters 184
10.2.2 Character class escapes 185
10.2.2.1 Single-character escapes 186
10.2.2.2 Multi-character escapes 186
10.2.2.3 Category escapes 188
10.2.2.4 Block escapes 190
10.2.3 Character class expressions 195
10.2.3.1 Specifying a list of characters 195
10.2.3.2 Specifying a range 196
10.2.3.3 Combining characters and ranges 196
10.2.3.4 Negating a character class expression 197
10.2.3.5 Subtracting from a character class expression 197
10.2.4 Parenthesized regular expressions 198
10.3 Quantifiers 198
Chapter 11: Union and list types 202
11.1 Varieties and derivation types 203
11.2 Union types 205
11.2.1 Defining union types 205
11.2.2 Restricting union types 207
11.2.3 Unions of unions 208
11.2.4 Specifying the member type in the instance 208
11.3 List types 209
11.3.1 Defining list types 209
11.3.2 Design hint: When should I use lists? 211
11.3.3 Restricting list types 212
11.3.3.1 Length facets 212
11.3.3.2 Enumeration facet 214
11.3.3.3 Pattern facet 215
11.3.4 Lists and strings 216
11.3.5 Lists of unions 217
11.3.6 Lists of lists 218
11.3.7 Restricting the item type 219
Chapter 12: Built-in simple types 220
12.1 Built-in types 221
12.2 String-based types 223
12.2.1 string, normalizedString, and token 223
12.2.1.1 Design hint: Should I use string, normalizedString, or token? 225
12.2.2 Name 227
12.2.3 NCName 227
12.2.4 language 228
12.3 Numeric types 231
12.3.1 float and double 231
12.3.2 decimal 231
12.3.3 Integer types 233
12.3.3.1 Design hint: Is it an integer or a string? 234
12.4 Date and time types 237
12.4.1 date 237
12.4.2 time 238
12.4.3 dateTime 239
12.4.4 gYear 239
12.4.5 gYearMonth 240
12.4.6 gMonth 242
12.4.7 gMonthDay 242
12.4.8 gDay 243
12.4.9 duration 244
12.4.10 Representing time zones 245
12.4.11 Facets 246
12.4.12 Date and time ordering 247
12.5 Legacy types 247
12.5.1 ID 247
12.5.2 IDREF 249
12.5.3 IDREFS 250
12.5.4 ENTITY 251
12.5.5 ENTITIES 252
12.5.6 NMTOKEN 254
12.5.7 NMTOKENS 255
12.5.8 NOTATION 256
12.6 Other types 256
12.6.1 QName 256
12.6.2 boolean 258
12.6.3 hexBinary and base64Binary 259
12.6.4 anyURI 259
12.7 Type equality 262
Chapter 13: Complex types 266
13.1 What are complex types? 267
13.2 Defining complex types 268
13.2.1 Named complex types 268
13.2.2 Anonymous complex types 270
13.2.3 Complex type alternatives 271
13.3 Content types 272
13.3.1 Simple content 272
13.3.2 Element-only content 273
13.3.3 Mixed content 273
13.3.4 Empty content 275
13.4 Using element types 275
13.4.1 Local element declarations 276
13.4.2 Element references 276
13.4.3 Element wildcards 278
13.4.4 Duplication of element-type names 281
13.5 Using model groups 283
13.5.1 sequence groups 283
13.5.1.1 Design hint: Should I care about the order of elements? 285
13.5.2 choice groups 286
13.5.3 Nesting of sequence and choice groups 288
13.5.4 all groups 289
13.5.5 Named model group references 290
13.5.6 Deterministic content models 291
13.6 Using attributes 293
13.6.1 Local attribute declarations 293
13.6.2 Attribute references 294
13.6.3 Attribute wildcards 296
13.6.4 Attribute group references 297
Chapter 14: Deriving complex types 300
14.1 Why derive types? 301
14.2 Restriction and extension 302
14.3 Simple content and complex content 303
14.3.1 simpleContent elements 303
14.3.2 complexContent elements 303
14.4 Complex type extensions 305
14.4.1 Simple content extensions 306
14.4.2 Complex content extensions 306
14.4.2.1 Extending choice groups 309
14.4.3 Mixed content extensions 310
14.4.4 Empty content extensions 310
14.4.5 Attribute extensions 311
14.4.6 Attribute wildcard extensions 312
14.5 Complex type restrictions 314
14.5.1 Simple content restrictions 315
14.5.2 Complex content restrictions 317
14.5.2.1 Eliminating meaningless groups 319
14.5.2.2 Restricting element declarations 319
14.5.2.3 Restricting wildcards 321
14.5.2.4 Restricting groups 322
14.5.3 Mixed content restrictions 327
14.5.4 Empty content restrictions 329
14.5.5 Attribute restrictions 330
14.5.6 Attribute wildcard restrictions 331
14.6 Type substitution 334
14.7 Controlling type derivation and substitution 335
14.7.1 final: Preventing complex type derivation 336
14.7.2 block: Blocking substitution of derived types 336
14.7.3 Blocking type substitution in element declarations 338
14.7.4 abstract: Forcing derivation 339
Chapter 15: Reusable groups 342
15.1 Why reusable groups? 343
15.2 Named model groups 344
15.2.1 Defining named model groups 344
15.2.2 Referencing named model groups 346
15.2.2.1 Group references 347
15.2.2.2 Referencing a named model group in a complex type 347
15.2.2.3 Using all in named model groups 349
15.2.2.4 Named model groups referencing named model groups 349
15.3 Attribute groups 351
15.3.1 Defining attribute groups 351
15.3.2 Referencing attribute groups 353
15.3.2.1 Attribute group references 353
15.3.2.2 Referencing attribute groups in complex types 354
15.3.2.3 Duplicate attribute names 355
15.3.2.4 Duplicate attribute wildcard handling 355
15.3.2.5 Attribute groups referencing attribute groups 356
15.4 Reusable groups vs. complex type derivations 357
Chapter 16: Substitution groups 360
16.1 Why substitution groups? 361
16.2 The substitution group hierarchy 362
16.3 Declaring a substitution group 363
16.4 Type constraints for substitution groups 365
16.5 Alternatives to substitution groups 367
16.5.1 Reusable choice groups 367
16.5.2 Substituting a derived type in the instance 369
16.6 Controlling substitution groups 371
16.6.1 final: Preventing substitution group declarations 371
16.6.2 block: Blocking substitution in instances 373
16.6.3 abstract: Forcing substitution 373
Chapter 17: Identity constraints 376
17.1 Identity constraint categories 377
17.2 Design hint: Should I use ID/IDREF or key/keyref? 378
17.3 Structure of an identity constraint 378
17.4 Uniqueness constraints 380
17.5 Key constraints 382
17.6 Key references 383
17.6.1 Key references and type equality 386
17.7 Selectors and fields 387
17.7.1 Selectors 387
17.7.2 Fields 387
17.8 The XML Schema XPath subset 388
17.9 Identity constraints and namespaces 390
Chapter 18: Redefining schema components 396
18.1 Redefinition basics 397
18.1.1 Include plus redefine 399
18.1.2 Redefine and namespaces 399
18.1.3 Pervasive impact 399
18.2 The mechanics of redefinition 400
18.3 Redefining simple types 401
18.4 Redefining complex types 402
18.5 Redefining named model groups 404
18.5.1 Defining a subset 405
18.5.2 Defining a superset 406
18.6 Redefining attribute groups 407
18.6.1 Defining a subset 407
18.6.2 Defining a superset 409
Chapter 19: Topics for DTD users 412
19.1 Element declarations 413
19.1.1 Simple types 413
19.1.2 Complex types with simple content 415
19.1.3 Complex types with complex content 415
19.1.4 Mixed content 418
19.1.5 Empty content 419
19.1.6 Any content 420
19.2 Attribute declarations 420
19.2.1 Attribute types 420
19.2.2 Enumerated attribute types 421
19.2.3 Notation attributes 422
19.2.4 Default values 422
19.3 Notations 423
19.4 Parameter entities for reuse 424
19.4.1 Reusing content models 424
19.4.2 Reusing attributes 425
19.5 Parameter entities for extensibility 425
19.5.1 Extensions for sequence groups 426
19.5.2 Extensions for choice groups 428
19.5.3 Attribute extensions 430
19.5.4 Attribute group extensions 430
19.6 External parameter entities 431
19.7 General entities 433
19.7.1 Character and other parsed entities 433
19.7.2 Unparsed entities 433
19.8 Comments 434
19.9 Using DTDs and schemas together 436
Chapter 20: Naming considerations 438
20.1 Naming guidelines 439
20.1.1 Rules for valid XML names 440
20.1.2 Separators 440
20.1.3 Name length 441
20.1.4 Standard terms and abbreviations 441
20.1.5 Use of subject terms 441
20.2 Qualified vs. unqualified names 444
20.2.1 Qualified local names 444
20.2.2 Unqualified local names 445
20.2.3 Using elementFormDefault 445
20.2.4 Form and global element declarations 447
20.2.5 Default namespaces and unqualified names 447
20.2.6 Design hint: Should I use qualified or unqualified local names? 448
20.2.7 Qualified vs. unqualified attribute names 449
20.3 Structuring namespaces 450
20.3.1 Same namespace 451
20.3.2 Different namespaces 453
20.3.3 Chameleon namespaces 458
20.4 Multiple languages 460
Chapter 21: Extensibility and reuse 464
21.1 Reuse 466
21.2 Extending schemas 467
21.2.1 Wildcards 468
21.2.2 Type derivation 471
21.2.3 Substitution groups 473
21.2.4 Type redefinition 475
21.2.5 Named model group redefinition 477
21.3 Versioning of schemas 478
21.3.1 Schema compatibility 479
21.3.2 Application compatibility 480
21.3.3 Conversion capability 481
21.3.4 Using version numbers 481
21.4 Designing applications to support change 482
Appendix A: Table of XSDL keywords 484
A.1 XSDL element types 485
A.2 XSDL attributes 494
Appendix B: Built-in simple types 504
B.1 Built-in simple types 505
Index 511