Java Parallels

As the XML Schema specification has solidified, the similarity between XML Schema and Java class and interface definitions has only increased. Although still strictly only a set of constraints, an XML Schema closely models the code you write in Java when creating a class or interface definition. The schema defines the set of allowed data that is contained within an XML document; this is similar to the way a Java class or interface defines the allowed methods and variables that an instance of the class may represent. Just as a Java program only needs to know this definition to use the instance (without having to know specific details about the instance implementation, such as its memory address or contents), an XML-aware application only needs to understand a document’s constraints (defined in the XML Schema) to use the XML document.

The importance of this parallel might not seem obvious to you; however, this facet of XML Schema is particularly critical to how XML may be used in new types of applications, and new implementations of old techniques. We look at just a few of these important applications here, but you should be able to extend these concepts to many more uses, perhaps pushing the envelope of your own applications’ functionality.

Equivalence

One important concept that XML Schema introduces is element equivalence. In XML 1.0 and DTDs, one element type must be mapped to one element. In other words, if two elements shared identical content, both elements had ...

Get Java and XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.