Home > Articles > Web Services > XML

Schema Extensibility and the any Element

  • Print
  • + Share This
Two of the most powerful and interesting aspects of XML Schema are the creation of extensible schemas and using XML Schema as a portable type system. Unfortunately, these two features are among the most difficult to understand and apply. This article provides some basic guidance on applying these features in your applications.
Jim Webber is a coauthor of Developing Enterprise Web Services: An Architect's Guide (Prentice-Hall PTR, 2003, ISBN 0131401602). This article is derived from Chapter 2 of the book.
From the author of

Part 1 of this article showed the basic nuts and bolts of XML Schema and how to apply those features to constraining XML documents. The real power of XML Schema is unleashed when you use it not only to convey document structure, but as a platform-independent metadata language. This article explores features of XML Schema that allow the construction of other schemas that you can extend, and describes how to capture type information in your schemas.


By default, all complex types that you create in a custom XML schema have closed content models. This means that only the elements that are specified when the type is declared can appear in instances. While this setup certainly encourages strong typing, it can also be a problem: How do you handle elements within a document that you can't predict ahead of time? Fortunately, this kind of extensibility is supported in XML Schema through use of the any element, which allows you to develop an open content model for a type through the use of wildcards.

Using any within a complex type means that any element can appear at that location, becoming a placeholder for future content that you can't predict while building the type. For attributes, anyAttribute defines placeholders for future attribute extensions.

Of course, you might not want completely arbitrary content to be embedded, so any can be constrained in a number of ways. Don't worry: It will still be very generic even after the constraints!

  • + Share This
  • 🔖 Save To Your Account