XML Schema Bindings

Moving more into the Java side of things, one major aspect of XML programming I expect to see is a set of datatypes defined in Java that represent XML Schema constructs. This is somewhat similar to the DOM Level 2 HTML bindings I talked about in Chapter 6. I consider these infinitely more useful. Because an XML Schema is itself an XML document, it can be parsed and dealt with like any other XML document. However, trying to work with an XML Schema as just any old XML document turns out to be a bit of a pain. You can’t, for example, query an element definition and determine if it is a complex type. Instead, you have to get the element, see if it has any children, determine if one of those children is named complexType, and so on. This gets even worse when things like sequencing are used; suddenly the complex type definition appears nested two levels deep.

What I expect to see (and in fact, already hear rumblings of) is a grammar and set of Java objects built to specifically match up with XML Schema datatypes. This would presumably be built on an existing object-based API, like DOM or JDOM. So, for the sake of example, assume that DOM Level 4 or JDOM 1.1 define such objects. You might see code like this:

// THIS CODE IS PURELY HYPOTHETICAL
XSDDocumentParser schemaParser =
    new org.apache.xerces.parsers.XSDParser( );
parser.parse(mySchema);
XSDDocument doc = parser.getXSDDocument( );

Now, instead of working with root elements and attributes in XML, you would deal ...

Get Java and XML, Second Edition 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.