Definitive XML Schema (Charles F. Goldfarb Definitive Xml Series) [NOOK Book]

Overview

The authoritative XML Schema reference and tutorial!

  • Leverage the full power of XML Schema!
  • In-depth coverage of the approved W3C Recommendation
  • Schema design–practical and thorough
  • Transition help for experienced DTD developers
  • Authoritative! By Priscilla Walmsley–a member of the W3C XML Schema Working ...
See more details below
Definitive XML Schema (Charles F. Goldfarb Definitive Xml Series)

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac

Want a NOOK? Explore Now

NOOK Book (eBook)
$26.99
BN.com price
(Save 42%)$46.99 List Price

Overview

The authoritative XML Schema reference and tutorial!

  • Leverage the full power of XML Schema!
  • In-depth coverage of the approved W3C Recommendation
  • Schema design–practical and thorough
  • Transition help for experienced DTD developers
  • Authoritative! By Priscilla Walmsley–a member of the W3C XML Schema Working Group

To leverage the full power of XML, companies need shared vocabularies to base their documents and scripts upon. XML Schema makes it possible to create those shared vocabularies-and Definitive XML Schema is the authoritative guide to the standard! Written by Priscilla Walmsley, a member of the W3C working group that created XML Schema, this book explains the W3C Recommendation with unprecedented insight and clarity–and introduces practical techniques for writing schemas to support any B2B, Web service, or content processing application. Coverage includes:

  • How XML Schema provides a rigorous, complete standard for modeling XML document structure, content, and datatypes
  • Working with schemas: Schema composition, instance validation, documentation, namespaces, and more
  • XML Schema building blocks: elements, attributes, and types
  • Advanced techniques: type derivation, model groups, substitution groups, identity constraints, redefinition, and much more
  • An in-depth primer on effective schema design, including naming, document structure, and extensibility considerations
  • Transition guidance for experienced DTD developers

Definitive XML Schema brings together expert guidance for schema design, superior approaches to schema development, and the most systematic XML Schema reference on the market. Whether you're a developer, architect, or content specialist, it's the only XML Schema resource you need!

"XML Schema is an incredibly powerful-and complex-document schema language, with such new capabilities as strong typing, modularity, inheritance, and identity constraints. This book guides you through the complexity so you can confidently use that power for your own projects."

–Charles F. Goldfarb

Read More Show Less

Editorial Reviews

From The Critics
Written by a member of the W3C working group that created the XML Schema for creating shared vocabularies, this book explains the W3C Recommendation from an insider's perspective and introduces practical techniques for writing schemas to support any business-to-business Web service. Walmsley, a software architect specializing in XML architecture and data management, shows how the XML Schema provides a standard for modeling XML document structure, explains how to work with schemas, and describes advanced techniques. She also provides an in-depth primer on effective schema design, and transition guidance for experienced DTD developers. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780321629937
  • Publisher: Pearson Education
  • Publication date: 12/21/2001
  • Series: Charles F. Goldfarb Definitive XML Series
  • Sold by: Barnes & Noble
  • Format: eBook
  • Edition number: 1
  • Pages: 560
  • File size: 9 MB

Meet the Author

PRISCILLA WALMSLEY is a software architect at Vitria Technology, specializing in XML architecture and data management. She previously co-founded XMLSolutions Corporation. Walmsley has extensive expertise in electronic commerce, enterprise application integration, and data management, and has served with the W3C XML Schema Working Group since 1999.

About the Series Editor

Charles F. Goldfarb is the father of XML technology. He invented SGML,the Standard Generalized Markup Language on which XML and HTML arebased. You can find him on the Web at xmlbooks.com

Read More Show Less

Read an Excerpt

Chapter 9: Simple types

Both element and attribute declarations can use simple types to describe the data content of the components. This chapter introduces simple types, and explains how to define your own atomic simple types for use in your schemas.

9.1 Simple type varieties

There are three varieties of simple type: atomic types, list types, and union types.
  1. Atomic types have values that are indivisible, such as 10 and large.
  2. List types have values that are whitespace-separated lists of atomic values, such as <availableSizes>10 large 2</availableSizes>.
  3. Union types may have values that are either atomic values or list values. What differentiates them is that the set of valid values, or "value space," for the type is the union of the value spaces of two or more other simple types. For example, to represent a dress size, you may define a union type that allows a value to be either an integer from 2 through 18, or one of the string values small, medium, or large.
List and union types are covered in Chapter 11, "Union and list types."

9.1.1 Design hint: How much should I break down my data values?

Data values should be broken down to the most atomic level possible. This allows them to be processed in a variety of ways for different uses, such as display, mathematical operations, and validation. It is much easier to concatenate two data values back together than it is to split them apart. In addition, more granular data is much easier to validate. It is a fairly common practice to put a data value and its units in the same element, for example <length>3cm</length>. How-ever, the preferred approach is to have a separate data value, preferably an attribute, for the units, for example <length units="cm">3</length>.

Using a single concatenated value is limiting because:

  • It is extremely cumbersome to validate. You have to apply a complicated pattern that would need to change every time a unit type is added.
  • You cannot perform comparisons, conversions, or mathematical operations on the data without splitting it apart.
  • If you want to display the data item differently (for example, as "3 centimeters" or "3 cm" or just "3", you have to split it apart. This complicates the stylesheets and applications that process the instance document.
It is possible to go too far, though. For example, you may break a date down as follows:
<orderDate>
<year>2001</year>
<month>06</month>
<day>15</day>
</orderDate>

This is probably an overkill unless you have a special need to process these items separately.

9.2 Simple type definitions

9.2.1 Named simple types

Simple types can be either named or anonymous. Named simple types are always defined globally (i.e., their parent is always schema or redefine) and are required to have a name that is unique among the data types (both simple and complex) in the schema. The XSDL syntax for a named simple type definition is shown in Table 9–1.

The name of a simple type must be an XML non-colonized name, which means that it must start with a letter or underscore, and may only contain letters, digits, underscores, hyphens, and periods. You cannot include a namespace prefix when defining the type; it takes its namespace from the target namespace of the schema document. All of the examples of named types in this book have the word "Type" at the end of their names, to clearly distinguish them from element-type names and attribute names. However, this is not a requirement; you may in fact have a data type definition and an element declaration using the same name.

Example 9–1 shows the definition of a named simple type Dress-SizeType, along with an element declaration that references it. Named types can be used in multiple element and attribute declarations.

Example 9–1. Defining and referencing a named simple type

<xsd:simpleType name="DressSizeType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="2"/>
<xsd:maxInclusive value="18"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="size" type="DressSizeType"/>

9.2.2 Anonymous simple types

Anonymous types, on the other hand, must not have names. They are always defined entirely within an element or attribute declaration, and may only be used once, by that declaration. Defining a type anonymously prevents it from ever being restricted, used in a list or union, or redefined. The XSDL syntax to define an anonymous simple type is shown in Table 9–2.

Example 9–2 shows the definition of an anonymous simple type within an element declaration.

Example 9–2. Defining an anonymous simple type

<xsd:element name="size">
<xsd:simpleType>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="2"/>
<xsd:maxInclusive value="18"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>

9.2.3 Design hint: Should I use named or anonymous types?

The advantage of named types is that they may be defined once and used many times. For example, you may define a type named Product-CodeType that lists all of the valid product codes in your organization.

This type can then be used in many element and attribute declarations in many schemas. This has the advantages of:

  • encouraging consistency throughout the organization,
  • reducing the possibility of error,
  • requiring less time to define new schemas,
  • simplifying maintenance, because new product codes need only be added in one place.
Named types can also make the schema more readable, when the type definitions are complex.

An anonymous type, on the other hand, can be used only in the element or attribute declaration that contains it. It can never be redefined, have types derived from it, or be used in a list or union type. This can seriously limit its reusability, extensibility, and ability to change over time.

However, there are cases where anonymous types are preferable to named types. If the type is unlikely to ever be reused, the advantages listed above no longer apply. Also, there is such a thing as too much reuse. For example, if an element can contain the values 1 through 10, it does not make sense to try to define a data type named OneToTen-Type that is reused by other unrelated element declarations with the same value space. If the value space for one of the element declarations that uses the named data type changes, but the other element declarations do not change, it actually makes maintenance more difficult, because a new data type needs to be defined at that time.

In addition, anonymous types can be more readable when they are relatively simple. It is sometimes desirable to have the definition of the data type right there with the element or attribute declaration....

Read More Show Less

Table of Contents

Acknowledgements.


1. Schemas: An introduction.

What is an XML schema? The purpose of schemas. Schema design. Schema languages.



2. A quick tour of XML Schema.

An example schema. The components of XML Schema. Elements and attributes. Data types. Simple types. Complex types. Namespaces and XML Schema. Schema composition. Instances and schemas. Annotations. Advanced features.



3. Namespaces.

Namespaces in XML. The relationship between namespaces and schemas. Using namespaces in XSDL.



4. Schema composition.

Modularizing schema documents. Defining schema documents. Schema assembly. include, redefine, and import.



5. Instances and schemas.

Using the instance attributes. Schema processing. Relating instances to schemas. Using XSDL hints in the instance. Dereferencing namespaces. The root element. Using DTDs and schemas together. Using specific schema processors.



6. Schema documentation and extension.

The mechanics. User documentation. Application information. Notations.



7. Element declarations.

Global and local element declarations. Declaring the data types of elements. Default and fixed values. Nils and nillability. Qualified vs unqualified forms.



8. Attribute declarations.

Global and local attribute declarations. Assigning types to attributes. Default and fixed values. Qualified vs unqualified forms.



9. Simple types.

Simple type varieties. Simple type definitions. Simple type restrictions. Facets. Preventing simple type derivation.



10. Regular expressions.

The structure of a regular expression. Atoms. Quantifiers.



11. Union and list types.

Varieties and derivation types. Union types. List types.



12. Built-in simple types.

Built-in types. String-based types. Numeric types. Date and time types. Legacy types. Other types. Type equality.



13. Complex types.

What are complex types? Defining complex types. Content types. Using element types. Using model groups. Using attributes.



14. Deriving complex types.

Why derive types? Restriction and extension. Simple content and complex content. Complex type extensions. Complex type restrictions. Type substitution. Controlling type derivation and substitution.



15. Reusable groups.

Why reusable groups? Named model groups. Attribute groups. Reusable groups vs complex type derivations.



16. Substitution groups.

Why substitution groups? The substitution group hierarchy. Declaring a substitution group. Type constraints for substitution groups. Alternatives to substitution groups. Controlling substitution groups.



17. Identity constraints.

Identity constraint categories. Design hint: Should I use ID/IDREF or key/keyref? Structure of an identity constraint. Uniqueness constraints. Key constraints. Key references. Selectors and fields. The XML Schema XPath subset. Identity constraints and namespaces.



18. Redefining schema components.

Redefinition basics. The mechanics of redefinition. Redefining simple types. Redefining complex types. Redefining named model groups. Redefining attribute groups.



19. Topics for DTD users.

Element declarations. Attribute declarations. Notations. Parameter entities for reuse. Parameter entities for extensibility. External parameter entities. General entities. Comments. Using DTDs and schemas together.



20. Naming considerations.

Naming guidelines. Qualified vs unqualified names. Structuring namespaces. Multiple languages.



21. Extensibility and reuse.

Reuse. Extending schemas. Versioning of schemas. Designing applications to support change.



Appendix A: Table of XSDL keywords.

XSDL element types. XSDL attributes.



Appendix B: Built-in simple types.

Built-in simple types.



Index.

Read More Show Less

Preface

Schemas:An introduction

Chapter 1

This chapter provides a brief explanation of schemas and why they are important. It also discusses the basic schema design goals, and describes the various existing schema languages.

1.1 What is an XML schema?

The word schema means a diagram, plan, or framework. In XML, it refers to a document that describes an XML document. Suppose you have the XML instance shown in Example 1-1. It consists of a product element that has two children (number and size) and an attribute (effDate).

Example 1-2 shows a schema that describes the instance. It contains element and attribute declarations that assign data types and element-type names to elements and attributes.

Example 1-1. Product instance

557 10

Example 1-2. Product schema

1.2 The purpose of schemas

1.2.1 Data validation

One of the most common uses for schemas is to verify that an XML document is valid according to a defined set of rules. A schema can be used to validate:

  • The structure of elements and attributes. For example, a product must have a number and a size, and may optionally have an effDate (effective date).
  • The order of elements. For example, number must appear before size.
  • The data values of attributes and elements, based on ranges, enumerations, and pattern matching. For example, size must be an integer between 2 and 18, and effDate must be a valid date.
  • The uniqueness of values in an instance. For example, all product numbers in an instance must be unique.

1.2.2 A contract with trading partners

Often, XML instances are passed between organizations. A schema may act as a contract with your trading partners. It clearly lays out the rules for document structure and what is required. Since an instance can be validated against a schema, the "contract" can be enforced using available tools.

1.2.3 System documentation

Schemas can provide documentation about the data in an XML instance. Anyone who needs to understand the data can refer to the schema for information about names, structures, and data types of the items. To include further documentation, you can add annotations to any schema component.

1.2.4 Augmentation of data

Schema processing can also add to the instance. It inserts default and fixed values for elements and attributes, and normalizes whitespace according to the data type.

1.2.5 Application information

Schemas provide a way for additional information about the data to be supplied to the application when processing a particular type of document. For example, you could include information on how to map the product element instances to a database table, and have the application use this information to automatically update a particular table with the data.

In addition to being available at processing time, this information in schemas can be used to generate code such as:

  • User interfaces for editing the information. For example, if you know that size is between 2 and 18, you can generate an interface that has a slider bar with these values as the limits.
  • Stylesheets to transform the instance data into a reader-friendly representation such as XHTML. For example, if you know that the human-readable name for the content of a number element is "Product Number" you can use this as a column header.
  • Code to insert or extract the data from a database. For example, if you know that the product number maps to the PROD_NUM column on the PRODUCTS table, you can generate an efficient routine to insert it into that column.

Tools have only just begun to take advantage of the possibilities of schemas. In the coming years, we will see schemas used in many creative new ways.

1.3 Schema design

XML Schema is packed with features, and there are often several ways to accurately describe the same thing. The decisions made during schema design can affect its usability, accuracy, and applicability. Therefore, it is important to keep in mind your design objectives when creating a schema. These objectives may vary depending on how you are using XML, but some are common to all use cases.

1.3.1 Accuracy and precision

Obviously, a schema should accurately describe an XML instance and allow it to be validated. Schemas should also be precise in describing data. Precision can result in more complete validation as well as better documentation. Precision can be achieved by defining restrictive data types that truly represent valid values.

1.3.2 Clarity

Schemas should be very clear, allowing a reader to instantly understand the structure and characteristics of the instance being described. Clarity can be achieved by:

  • appropriate choice of names,
  • consistency in naming,
  • consistency in structure,
  • good documentation,
  • avoiding unnecessary complexity.

1.3.3 Broad applicability

There is a temptation to create schemas that are useful only for a specific application purpose. In some cases, this may be appropriate. However, it is better to create a schema that has broader applicability. For example, a business unit that handles only domestic accounts may not use a country element declaration as part of an address. They should consider adding it in as an optional element for the purposes of consis-tency and future usability.

There are two components to a schema's broad applicability: reusability and extensibility. Reusable schema components are modular and well documented, encouraging schema authors to reuse them in other schemas. Extensible components are flexible and open, allowing other schema authors to build on them for future uses. Since reusability and extensibility are important, all of Chapter 21, "Extensibility and reuse," is devoted to them.

1.4 Schema languages

1.4.1 Document Type Definitions (DTDs)

Document Type Definitions (DTDs) are a commonly used method of describing XML documents. They allow you to define the basic structure of an XML instance, including:

  • the structure and order of child elements in an element type,
  • the attributes of an element type,
  • basic data typing for attributes,
  • default and fixed values for attributes,
  • notations to represent other data formats.

Example 1-3 shows a DTD that is roughly equivalent to our schema in Example 1-2.

Example 1-3. Product DTD

DTDs have many advantages. They are relatively simple, have a compact syntax, and are widely understood by XML implementers. When designed well, they can be extremely modular, flexible, and extensible.

However, DTDs also have some shortcomings. They have their own non-XML syntax, do not support namespaces easily, and provide very limited data typing, for attributes only.

1.4.2 Enter schemas

As XML became increasingly popular for data applications such as e-commerce and enterprise application integration (EAI), a more robust schema language was needed. Specifically, XML developers wanted:

  • The ability to constrain data based on common data types such as integer and date.
  • The ability to define their own data types in order to further constrain data.
  • Support for namespaces.
  • The ability to specify multiple declarations for the same element-type name in different contexts.
  • Object oriented features such as type derivation. The ability to express types as extensions or restrictions of other types allows them to be processed similarly and substituted for each other.
  • A schema language that uses XML syntax. This is advantageous because it is extensible, can represent more advanced models and can be processed by many available tools.
  • The ability to add structured documentation and application information that is passed to the application during processing.

DTDs are not likely to disappear now that schemas have arrived on the scene. They are supported in many tools, are widely understood, and are currently in use in many applications. In addition, they continue to be useful as a lightweight alternative to schemas.

1.4.3 W3C XML Schema

Four schema languages were developed before work began on XML Schema: XDR (XML Data Reduced), DCD, SOX, and DDML. These four languages were considered together as a starting point for XML Schema, and many of their originators were involved in the creation of XML Schema.

The World Wide Web Consortium (W3C) began work on XML Schema in 1998. The first version, upon which this book is based, became an official Recommendation on May 2, 2001. The formal Recommendation is in three parts:

  • XML Schema Part 0: Primer is a non-normative introduction to XML Schema that provides a lot of examples and explanations. It can be found at http://www.w3.org/TR/xmlschema-0/
  • XML Schema Part 1: Structures describes most of the components of XML Schema. It can be found at http://www.w3.org/TR/xmlschema-1/
  • XML Schema Part 2: Datatypes covers simple data types. It explains the built-in data types and the facets that may be used to restrict them. It is a separate document so that other specifications may use it, without including all of XML Schema. It can be found at http://www.w3.org/TR/xmlschema-2/

1.4.4 Notes on terminology

1.4.4.1 Schema

"XML Schema" is the official name of the Recommendation and is also sometimes used to refer to conforming schema documents. In order to clearly distinguish between the two, this book uses the term "XML Schema" only to mean the Recommendation itself.

A "schema definition" is the formal expression of a schema.

The initialism "XSDL" (XML Schema Definition Language) is used to refer to the language that is used to create schema definitions in XML. In other words, XSDL is the markup language that uses elements such as schema and complexType.

The term "schema document" is used to refer to an XML document that is written in XSDL, with a schema element as its root. The extension "xsd" is used in the file identifiers of such documents. A schema definition may consist of one or more schema documents, as described in Chapter 4, "Schema composition."

As it is unlikely to cause confusion in this book, for simplicity the word "schema" will be used to refer to both a schema as a concept, and an actual schema definition that conforms to the XML Schema definition language.

1.4.4.2 Type

According to the XML Recommendation, every XML element has an element type. In fact, it is the name of the element type that occurs in the start- and end-tags, as individual elements do not have names (although they may have IDs).

XML Schema, however, uses the word "type" exclusively as a shorthand to refer to simple types and complex types. Perhaps to avoid confusion with this usage, the Recommendation does not use the phrase "element type" in conjunction with schemas. This book follows that same practice and generally doesn't speak of element types per se, although it does refer to "element-type names" where appropriate.

1.4.5 Additional schema languages

XML Schema is not the only schema language that is currently in use. While it is very robust, it is not always the most appropriate schema language for all cases. This section describes two other schema languages.

1.4.5.1 RELAX NG

RELAX NG covers some of the same ground as XML Schema. As of this writing, it is currently being developed by an OASIS technical committee. RELAX NG is intended only for validation; the processor does not pass documentation or application information from the schema to the application. RELAX NG does not have built-in data types; it is designed to use other data type libraries (such as that of XML Schema).

RELAX NG has some handy features that are not currently part of XML Schema:

  • It includes attributes in the elements' content models. For example, you can specify that a product element must either have an effectiveDate attribute or a startDate attribute. XML Schema does not currently provide a way to do this.
  • It allows a content model to depend on the value of an attribute. For example, if the value of the type attribute of a product element is shirt, this product element can contain a size child. If it is umbrella, it cannot. XML Schema provides a similar mechanism through type substitution, but it is less flexible.
  • It allows you to specify a content model such as "one number, one size, and up to three color elements, in any order." This is quite cumbersome to express in XML Schema if you do not want to enforce a particular order.
  • It does not require content models to be deterministic. This is explained in Section 13.5.6, "Deterministic content models."

However, RELAX NG also has some limitations compared to XML Schema:

  • It has no inheritance capabilities. XML Schema's restriction and extension mechanisms allow type substitution and many other benefits, described in Section 14.1, "Why derive types?"
  • Because it is only intended for validation, it does not provide application information to the processor. In fact, the RELAX NG processor passes the exact same information that is available from a DTD to the application. This is not a disadvantage if your only objective is validation, but it does not allow you to use the schema to help you understand how to process the instance.

For more information on RELAX NG, see http://www.oasis-open.org/committees/relax-ng/

1.4.5.2 Schematron

Schematron takes a different approach from XML Schema and RELAX NG. XML Schema and RELAX NG are both grammar-based schema languages. They specify what must appear in an instance, and in what order.

By contrast, Schematron is rule-based. It allows you to define a series of rules to which the document must conform. These rules are expressed using XPath. In contrast to grammar-based languages, Schematron considers anything that does not violate a rule to be valid. There is no need to declare every element type or attribute that may appear in the instance.

Like RELAX NG, Schematron is intended only for validation of instances. It has a number of advantages:

  • It is very easy to learn and use. It uses XPath, which is familiar to many people already using XML.
  • The use of XPath allows it to very flexibly and succinctly express relationships between elements in a way that is not possible with other schema languages.
  • The values in an instance can be involved in validation. For example, in XSDL it is not possible to express "If the value of newCustomer is false, then customerID must appear." Schematron allows such co-occurrence constraints.

The limitations of Schematron compared to XML Schema are:

  • It does not provide a model of the instance data. A person cannot gain an understanding of what instance data is expected by looking at the schema.
  • It is intended only for validation, and it cannot be used to pass any information about the instance, such as data types or default values, to an application.
  • Anything is valid unless it is specifically prohibited. This puts a burden to anticipate all possible errors on the schema author.

Because Schematron and XML Schema complement each other, it makes sense to combine the two. An example of embedding a Schematron schema in XSDL is provided in Section 6.3.2, "Schematron for co-occurrence constraints." For more information on Schematron, see http://www.ascc.net/xml/resource/schematron/schema-tron.html

Read More Show Less

Customer Reviews

Average Rating 5
( 1 )
Rating Distribution

5 Star

(1)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted Mon Feb 18 00:00:00 EST 2002

    excellent information

    This book answered my questions about XMLSchema. Prior to reading it I felt intimidated by the W3C XMLSchema specification. Now, I understand further why Schema's are so valuable and necessary. Several other technical books I have read seem to be simple paraphrases of W3C specifications. However, this book is very well written and full of clear examples.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)