SKIP THE SHIPPING
Use code NOSHIP during checkout to save 40% on eligible eBooks, now through January 5. Shop now.
Register your product to gain access to bonus material or receive a coupon.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
“XML Schema 1.1 has gone from strong data typing to positively stalwart—so powerful it can enforce database level constraints and business rules, so your data transfer code won’t have to. This book covers the 1.1 changes—and more—in its 500 revisions to Priscilla Walmsley’s 10-year best-selling classic. It’s the guide you need to navigate XML Schema’s complexity—and master its power!”
—Charles F. Goldfarb
For Ten Years the World’s Favorite Guide to XML Schema—Now Extensively Revised for Version 1.1 and Today’s Best Practices!
To leverage XML’s full power, organizations need shared vocabularies based on XML Schema. For a full decade, Definitive XML Schema has been the most practical, accessible, and usable guide to working with XML Schema. Now, author Priscilla Walmsley has thoroughly updated her classic to fully reflect XML Schema 1.1, and to present new best practices for designing successful schemas.
Priscilla helped create XML Schema as a member of the W3C XML Schema Working Group, so she is well qualified to explain the W3C recommendation with insight and clarity. Her book teaches practical techniques for writing schemas to support any application, including many new use cases. You’ll discover how XML Schema 1.1 provides a rigorous, complete specification for modeling XML document structure, content, and datatypes; and walk through the many aspects of designing and applying schemas, including composition, instance validation, documentation, and namespaces. Then, building on the fundamentals, Priscilla introduces powerful advanced techniques ranging from type derivation to identity constraints. This edition’s extensive new coverage includes
If you’re an XML developer, architect, or content specialist, with this Second Edition you can join the tens of thousands who rely on Definitive XML Schema for practical insights, deeper understanding, and solutions that work.
Foreword xxxi
Acknowledgments xxxiii
How to use this book xxxv
Chapter 1 Schemas: An introduction 2
1.1 What is a schema? 3
1.2 The purpose of schemas 5
1.2.1 Data validation 5
1.2.2 A contract with trading partners 5
1.2.3 System documentation 6
1.2.4 Providing information to processors 6
1.2.5 Augmentation of data 6
1.2.6 Application information 6
1.3 Schema design 7
1.3.1 Accuracy and precision 7
1.3.2 Clarity 8
1.3.3 Broad applicability 8
1.4 Schema languages 9
1.4.1 Document Type Definition (DTD) 9
1.4.2 Schema requirements expand 10
1.4.3 W3C XML Schema 11
1.4.4 Other schema languages 12
1.4.4.1 RELAX NG 12
1.4.4.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 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 29
2.9 Instances and schemas 30
2.10 Annotations 31
2.11 Advanced features 32
2.11.1 Named groups 32
2.11.2 Identity constraints 32
2.11.3 Substitution groups 32
2.11.4 Redefinition and overriding 33
2.11.5 Assertions 33
Chapter 3 Namespaces 34
3.1 Namespaces in XML 35
3.1.1 Namespace names 36
3.1.2 Namespace declarations and prefixes 37
3.1.3 Default namespace declarations 39
3.1.4 Name terminology 40
3.1.5 Scope of namespace declarations 41
3.1.6 Overriding namespace declarations 42
3.1.7 Undeclaring namespaces 43
3.1.8 Attributes and namespaces 44
3.1.9 A summary example 46
3.2 The relationship between namespaces and schemas 48
3.3 Using namespaces in schemas 48
3.3.1 Target namespaces 48
3.3.2 The XML Schema Namespace 50
3.3.3 The XML Schema Instance Namespace 51
3.3.4 The Version Control Namespace 51
3.3.5 Namespace declarations in schema documents 52
3.3.5.1 Map a prefix to the XML Schema Namespace 52
3.3.5.2 Map a prefix to the target namespace 53
3.3.5.3 Map prefixes to all namespaces 54
Chapter 4 Schema composition 56
4.1 Modularizing schema documents 57
4.2 Defining schema documents 58
4.3 Combining multiple schema documents 61
4.3.1 include 62
4.3.1.1 The syntax of includes 63
4.3.1.2 Chameleon includes 65
4.3.2 import 66
4.3.2.1 The syntax of imports 67
4.3.2.2 Multiple levels of imports 70
4.3.2.3 Multiple imports of the same namespace 72
4.4 Schema assembly considerations 75
4.4.1 Uniqueness of qualified names 75
4.4.2 Missing components 76
4.4.3 Schema document defaults 77
Chapter 5 Instances and schemas 78
5.1 Using the instance attributes 79
5.2 Schema processing 81
5.2.1 Validation 81
5.2.2 Augmenting the instance 82
5.3 Relating instances to schemas 83
5.3.1 Using hints in the instance 84
5.3.1.1 The xsi:schemaLocation attribute 84
5.3.1.2 The xsi:noNamespaceSchemaLocation attribute 86
5.4 The root element 87
Chapter 6 Element declarations 88
6.1 Global and local element declarations 89
6.1.1 Global element declarations 89
6.1.2 Local element declarations 93
6.1.3 Design hint: Should I use global or local element
declarations? 95
6.2 Declaring the types of elements 96
6.3 Qualified vs. unqualified forms 98
6.3.1 Qualified local names 98
6.3.2 Unqualified local names 98
6.3.3 Using elementFormDefault 99
6.3.4 Using form 100
6.3.5 Default namespaces and unqualified names 101
6.4 Default and fixed values 101
6.4.1 Default values 102
6.4.2 Fixed values 103
6.5 Nils and nillability 105
6.5.1 Using xsi:nil in an instance 108
6.5.2 Making elements nillable 109
Chapter 7 Attribute declarations 112
7.1 Attributes vs. elements 113
7.2 Global and local attribute declarations 115
7.2.1 Global attribute declarations 115
7.2.2 Local attribute declarations 117
7.2.3 Design hint: Should I use global or local attributedeclarations? 119
7.3 Declaring the types of attributes 120
7.4 Qualified vs. unqualified forms 122
7.5 Default and fixed values 123
7.5.1 Default values 124
7.5.2 Fixed values 125
7.6 Inherited attributes 126
Chapter 8 Simple types 128
8.1 Simple type varieties 129
8.1.1 Design hint: How much should I break down my datavalues? 130
8.2 Simple type definitions 131
8.2.1 Named simple types 131
8.2.2 Anonymous simple types 132
8.2.3 Design hint: Should I use named or anonymous types? 133
8.3 Simple type restrictions 135
8.3.1 Defining a restriction 136
8.3.2 Overview of the facets 137
8.3.3 Inheriting and restricting facets 139
8.3.4 Fixed facets 140
8.3.4.1 Design hint: When should I fix a facet? 141
8.4 Facets 142
8.4.1 Bounds facets 142
8.4.2 Length facets 143
8.4.2.1 Design hint: What if I want to allow empty values? 143
8.4.2.2 Design hint: What if I want to restrict the length of an integer? 144
8.4.3 totalDigits and fractionDigits 145
8.4.4 Enumeration 145
8.4.5 Pattern 148
8.4.6 Assertion 150
8.4.7 Explicit Time Zone 150
8.4.8 Whitespace 151
8.5 Preventing simple type derivation 152
8.6 Implementation-defined types and facets 154
8.6.1 Implementation-defined types 154
8.6.2 Implementation-defined facets 155
Chapter 9 Regular expressions 158
9.1 The structure of a regular expression 159
9.2 Atoms 161
9.2.1 Normal characters 162
9.2.2 The wildcard escape character 164
9.2.3 Character class escapes 164
9.2.3.1 Single-character escapes 165
9.2.3.2 Multicharacter escapes 166
9.2.3.3 Category escapes 167
9.2.3.4 Block escapes 170
9.2.4 Character class expressions 171
9.2.4.1 Listing individual characters 171
9.2.4.2 Specifying a range 172
9.2.4.3 Combining individual characters and ranges 173
9.2.4.4 Negating a character class expression 173
9.2.4.5 Subtracting from a character class expression 174
9.2.4.6 Escaping rules for character class expressions 175
9.2.5 Parenthesized regular expressions 175
9.3 Quantifiers 176
9.4 Branches 177
Chapter 10 Union and list types 180
10.1 Varieties and derivation types 181
10.2 Union types 183
10.2.1 Defining union types 183
10.2.2 Restricting union types 185
10.2.3 Unions of unions 186
10.2.4 Specifying the member type in the instance 187
10.3 List types 188
10.3.1 Defining list types 188
10.3.2 Design hint: When should I use lists? 189
10.3.3 Restricting list types 190
10.3.3.1 Length facets 192
10.3.3.2 Enumeration facet 192
10.3.3.3 Pattern facet 194
10.3.4 Lists and strings 195
10.3.5 Lists of unions 196
10.3.6 Lists of lists 196
10.3.7 Restricting the item type 198
Chapter 11 Built-in simple types 200
11.1 The XML Schema type system 201
11.1.1 The type hierarchy 202
11.1.2 Value spaces and lexical spaces 204
11.1.3 Facets and built-in types 204
11.2 String-based types 205
11.2.1 string, normalizedString, and token 205
11.2.1.1 Design hint: Should I use string, normalizedString, or token? 207
11.2.2 Name 208
11.2.3 NCName 210
11.2.4 language 211
11.3 Numeric types 213
11.3.1 float and double 213
11.3.2 decimal 215
11.3.3 Integer types 217
11.3.3.1 Design hint: Is it an integer or a string? 220
11.4 Date and time types 221
11.4.1 date 221
11.4.2 time 222
11.4.3 dateTime 223
11.4.4 dateTimeStamp 224
11.4.5 gYear 225
11.4.6 gYearMonth 226
11.4.7 gMonth 227
11.4.8 gMonthDay 227
11.4.9 gDay 228
11.4.10 duration 229
11.4.11 yearMonthDuration 231
11.4.12 dayTimeDuration 232
11.4.13 Representing time zones 233
11.4.14 Facets 234
11.4.15 Date and time ordering 235
11.5 Legacy types 236
11.5.1 ID 236
11.5.2 IDREF 237
11.5.3 IDREFS 239
11.5.4 ENTITY 240
11.5.5 ENTITIES 242
11.5.6 NMTOKEN 243
11.5.7 NMTOKENS 244
11.5.8 NOTATION 245
11.6 Other types 246
11.6.1 QName 246
11.6.2 boolean 247
11.6.3 The binary types 248
11.6.4 anyURI 250
11.7 Comparing typed values 253
Chapter 12 Complex types 256
12.1 What are complex types? 257
12.2 Defining complex types 258
12.2.1 Named complex types 258
12.2.2 Anonymous complex types 260
12.2.3 Complex type alternatives 261
12.3 Content types 262
12.3.1 Simple content 262
12.3.2 Element-only content 264
12.3.3 Mixed content 264
12.3.4 Empty content 265
12.4 Using element declarations 266
12.4.1 Local element declarations 266
12.4.2 Element references 267
12.4.3 Duplication of element names 268
12.5 Using model groups 270
12.5.1 sequence groups 270
12.5.1.1 Design hint: Should I care about the order of elements? 272
12.5.2 choice groups 273
12.5.3 Nesting of sequence and choice groups 275
12.5.4 all groups 276
12.5.5 Named model group references 278
12.5.6 Deterministic content models 279
12.6 Using attribute declarations 281
12.6.1 Local attribute declarations 281
12.6.2 Attribute references 282
12.6.3 Attribute group references 284
12.6.4 Default attributes 284
12.7 Using wildcards 284
12.7.1 Element wildcards 285
12.7.1.1 Controlling the namespace of replacement elements 287
12.7.1.2 Controlling the strictness of validation 287
12.7.1.3 Negative wildcards 289
12.7.2 Open content models 292
12.7.2.1 Open content in a complex type 292
12.7.2.2 Default open content 295
12.7.3 Attribute wildcards 298
Chapter 13 Deriving complex types 300
13.1 Why derive types? 301
13.2 Restriction and extension 302
13.3 Simple content and complex content 303
13.3.1 simpleContent elements 303
13.3.2 complexContent elements 304
13.4 Complex type extensions 305
13.4.1 Simple content extensions 306
13.4.2 Complex content extensions 307
13.4.2.1 Extending choice groups 309
13.4.2.2 Extending all groups 310
13.4.2.3 Extending open content 311
13.4.3 Mixed content extensions 312
13.4.4 Empty content extensions 313
13.4.5 Attribute extensions 314
13.4.6 Attribute wildcard extensions 315
13.5 Complex type restrictions 316
13.5.1 Simple content restrictions 317
13.5.2 Complex content restrictions 318
13.5.2.1 Eliminating meaningless groups 320
13.5.2.2 Restricting element declarations 321
13.5.2.3 Restricting wildcards 322
13.5.2.4 Restricting groups 324
13.5.2.5 Restricting open content 329
13.5.3 Mixed content restrictions 331
13.5.4 Empty content restrictions 332
13.5.5 Attribute restrictions 333
13.5.6 Attribute wildcard restrictions 335
13.5.7 Restricting types from another namespace 337
13.5.7.1 Using targetNamespace on element and attribute declarations 339
13.6 Type substitution 341
13.7 Controlling type derivation and substitution 343
13.7.1 final: Preventing complex type derivation 343
13.7.2 block: Blocking substitution of derived types 344
13.7.3 Blocking type substitution in element declarations 346
13.7.4 abstract: Forcing derivation 346
Chapter 14 Assertions 350
14.1 Assertions 351
14.1.1 Assertions for simple types 353
14.1.1.1 Using XPath 2.0 operators 355
14.1.1.2 Using XPath 2.0 functions 357
14.1.1.3 Types and assertions 359
14.1.1.4 Inheriting simple type assertions 362
14.1.1.5 Assertions on list types 363
14.1.2 Assertions for complex types 365
14.1.2.1 Path expressions 367
14.1.2.2 Conditional expressions 369
14.1.2.3 Assertions in derived complex types 370
14.1.3 Assertions and namespaces 372
14.1.3.1 Using xpathDefaultNamespace 373
14.2 Conditional type assignment 375
14.2.1 The alternative element 376
14.2.2 Specifying conditional type assignment 377
14.2.3 Using XPath in the test attribute 378
14.2.4 The error type 380
14.2.5 Conditional type assignment and namespaces 381
14.2.6 Using inherited attributes in conditional type Assignment 382
Chapter 15 Named groups 384
15.1 Why named groups? 385
15.2 Named model groups 386
15.2.1 Defining named model groups 386
15.2.2 Referencing named model groups 388
15.2.2.1 Group references 388
15.2.2.2 Referencing a named model group in a complex type 389
15.2.2.3 Using all in named model groups 391
15.2.2.4 Named model groups referencing named model groups 392
15.3 Attribute groups 392
15.3.1 Defining attribute groups 393
15.3.2 Referencing attribute groups 395
15.3.2.1 Attribute group references 395
15.3.2.2 Referencing attribute groups in complex types 396
15.3.2.3 Duplicate attribute names 397
15.3.2.4 Duplicate attribute wildcard handling 398
15.3.2.5 Attribute groups referencing attribute groups 398
15.3.3 The default attribute group 399
15.4 Named groups and namespaces 401
15.5 Design hint: Named groups or complex type derivations? 403
Chapter 16 Substitution groups 406
16.1 Why substitution groups? 407
16.2 The substitution group hierarchy 408
16.3 Declaring a substitution group 409
16.4 Type constraints for substitution groups 412
16.5 Members in multiple groups 413
16.6 Alternatives to substitution groups 414
16.6.1 Reusable choice groups 414
16.6.2 Substituting a derived type in the instance 415
16.7 Controlling substitution groups 418
16.7.1 final: Preventing substitution group declarations 418
16.7.2 block: Blocking substitution in instances 419
16.7.3 abstract: Forcing substitution 420
Chapter 17 Identity constraints 422
17.1 Identity constraint categories 423
17.2 Design hint: Should I use ID/IDREF or key/keyref? 424
17.3 Structure of an identity constraint 424
17.4 Uniqueness constraints 426
17.5 Key constraints 428
17.6 Key references 430
17.6.1 Key references and scope 432
17.6.2 Key references and type equality 432
17.7 Selectors and fields 433
17.7.1 Selectors 433
17.7.2 Fields 434
17.8 XPath subset for identity constraints 435
17.9 Identity constraints and namespaces 439
17.9.1 Using xpathDefaultNamespace 441
17.10 Referencing identity constraints 442
Chapter 18 Redefining and overriding schema components 446
18.1 Redefinition 448
18.1.1 Redefinition basics 448
18.1.1.1 Include plus redefine 450
18.1.1.2 Redefine and namespaces 450
18.1.1.3 Pervasive impact 450
18.1.2 The mechanics of redefinition 451
18.1.3 Redefining simple types 452
18.1.4 Redefining complex types 453
18.1.5 Redefining named model groups 454
18.1.5.1 Defining a subset 454
18.1.5.2 Defining a superset 455
18.1.6 Redefining attribute groups 456
18.1.6.1 Defining a subset 457
18.1.6.2 Defining a superset 458
18.2 Overrides 459
18.2.1 Override basics 459
18.2.1.1 Include plus override 461
18.2.1.2 Override and namespaces 461
18.2.1.3 Pervasive impact 462
18.2.2 The mechanics of overriding components 462
18.2.3 Overriding simple types 464
18.2.4 Overriding complex types 465
18.2.5 Overriding element and attribute declarations 466
18.2.6 Overriding named groups 467
18.3 Risks of redefines and overrides 468
18.3.1 Risks of redefining or overriding types 468
18.3.2 Risks of redefining or overriding named groups 470
Chapter 19 Topics for DTD users 472
19.1 Element declarations 473
19.1.1 Simple types 474
19.1.2 Complex types with simple content 475
19.1.3 Complex types with complex content 476
19.1.4 Mixed content 478
19.1.5 Empty content 479
19.1.6 Any content 480
19.2 Attribute declarations 480
19.2.1 Attribute types 480
19.2.2 Enumerated attribute types 481
19.2.3 Notation attributes 482
19.2.4 Default values 482
19.3 Parameter entities for reuse 483
19.3.1 Reusing content models 484
19.3.2 Reusing attributes 485
19.4 Parameter entities for extensibility 486
19.4.1 Extensions for sequence groups 486
19.4.2 Extensions for choice groups 489
19.4.3 Attribute extensions 490
19.5 External parameter entities 492
19.6 General entities 493
19.6.1 Character and other parsed entities 493
19.6.2 Unparsed entities 493
19.7 Notations 493
19.7.1 Declaring a notation 494
19.7.2 Declaring a notation attribute 495
19.7.3 Notations and unparsed entities 496
19.8 Comments 497
19.9 Using DTDs and schemas together 499
Chapter 20 XML information modeling 500
20.1 Data modeling paradigms 502
20.2 Relational models 503
20.2.1 Entities and attributes 504
20.2.2 Relationships 507
20.2.2.1 One-to-one and one-to-many relationships 507
20.2.2.2 Many-to-many relationships 507
20.2.2.2.1 Approach #1: Use containment with repetition 508
20.2.2.2.2 Approach #2: Use containment with references 510
20.2.2.2.3 Approach #3: Use relationship elements 512
20.3 Modeling object-oriented concepts 514
20.3.1 Inheritance 514
20.3.2 Composition 519
20.4 Modeling web services 522
20.5 Considerations for narrative content 524
20.5.1 Semantics vs. style 524
20.5.1.1 Benefits of excluding styling 524
20.5.1.2 Rendition elements: “block” and “inline” 525
20.5.2 Considerations for schema design 526
20.5.2.1 Flexibility 526
20.5.2.2 Reusing existing vocabularies 526
20.5.2.3 Attributes are for metadata 526
20.5.2.4 Humans write the documents 527
20.6 Considerations for a hierarchical model 527
20.6.1 Intermediate elements 527
20.6.2 Wrapper lists 531
20.6.3 Level of granularity 532
20.6.4 Generic vs. specific elements 533
Chapter 21 Schema design and documentation 538
21.1 The importance of schema design 539
21.2 Uses for schemas 540
21.3 Schema design goals 542
21.3.1 Flexibility and extensibility 542
21.3.2 Reusability 543
21.3.3 Clarity and simplicity 545
21.3.3.1 Naming and documentation 545
21.3.3.2 Clarity of structure 546
21.3.3.3 Simplicity 546
21.3.4 Support for graceful versioning 547
21.3.5 Interoperability and tool compatibility 547
21.4 Developing a schema design strategy 548
21.5 Schema organization considerations 550
21.5.1 Global vs. local components 550
21.5.1.1 Russian Doll 551
21.5.1.2 Salami Slice 553
21.5.1.3 Venetian Blind 554
21.5.1.4 Garden of Eden 555
21.5.2 Modularizing schema documents 557
21.6 Naming considerations 559
21.6.1 Rules for valid XML names 559
21.6.2 Separators 560
21.6.3 Name length 560
21.6.4 Standard terms and abbreviations 561
21.6.5 Use of object terms 562
21.7 Namespace considerations 564
21.7.1 Whether to use namespaces 564
21.7.2 Organizing namespaces 565
21.7.2.1 Same namespace 565
21.7.2.2 Different namespaces 568
21.7.2.3 Chameleon namespaces 572
21.7.3 Qualified vs. unqualified forms 575
21.7.3.1 Qualified local names 575
21.7.3.2 Unqualified local names 576
21.7.3.3 Using form in schemas 576
21.7.3.4 Form and global element declarations 578
21.7.3.5 Default namespaces and unqualified names 578
21.7.3.6 Qualified vs. unqualified element names 579
21.7.3.7 Qualified vs. unqualified attribute names 580
21.8 Schema documentation 580
21.8.1 Annotations 581
21.8.2 User documentation 582
21.8.2.1 Documentation syntax 582
21.8.2.2 Data element definitions 584
21.8.2.3 Code documentation 585
21.8.2.4 Section comments 585
21.8.3 Application information 586
21.8.4 Non-native attributes 588
21.8.4.1 Design hint: Should I use annotations or non-native attributes? 589
21.8.5 Documenting namespaces 589
Chapter 22 Extensibility and reuse 594
22.1 Reuse 596
22.1.1 Reusing schema components 596
22.1.2 Creating schemas that are highly reusable 597
22.1.3 Developing a common components library 597
22.2 Extending schemas 599
22.2.1 Wildcards 601
22.2.2 Open content 604
22.2.3 Type substitution 605
22.2.4 Substitution groups 607
22.2.5 Type redefinition 609
22.2.6 Named group redefinition 611
22.2.7 Overrides 612
Chapter 23 Versioning 616
23.1 Schema compatibility 617
23.1.1 Backward compatibility 618
23.1.2 Forward compatibility 623
23.2 Using version numbers 626
23.2.1 Major and minor versions 626
23.2.2 Placement of version numbers 628
23.2.2.1 Version numbers in schema documents 628
23.2.2.2 Versions in schema locations 630
23.2.2.3 Versions in instances 631
23.2.2.4 Versions in namespace names 632
23.2.2.5 A combination strategy 633
23.3 Application compatibility 634
23.4 Lessening the impact of versioning 635
23.4.1 Define a versioning strategy 636
23.4.2 Make only necessary changes 636
23.4.3 Document all changes 637
23.4.4 Deprecate components before deleting them 638
23.4.5 Provide a conversion capability 639
23.5 Versions of the XML Schema language 639
23.5.1 New features in version 1.1 640
23.5.2 Forward compatibility of XML Schema 1.1 641
23.5.3 Portability of implementation-defined types and facets 642
23.5.3.1 Using typeAvailable and typeUnavailable 644
23.5.3.2 Using facetAvailable and facetUnavailable 645
Appendix A XSD keywords 648
A.1 Elements 649
A.2 Attributes 671
Appendix B Built-in simple types 690
B.1 Built-in simple types 691
B.2 Applicability of facets to built-in simple types 695
Index 699