Skip to Main Content
Java and XML, Second Edition
book

Java and XML, Second Edition

by Brett McLaughlin
August 2001
Intermediate to advanced content levelIntermediate to advanced
528 pages
14h 35m
English
O'Reilly Media, Inc.
Content preview from Java and XML, Second Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java and XML, 3rd Edition

Java and XML, 3rd Edition

Brett McLaughlin, Justin Edelson
Java & XML Data Binding

Java & XML Data Binding

Brett McLaughlin

Publisher Resources

ISBN: 0596001975Supplemental ContentCatalog PageErrata