XML, XML, XML, XML. You can see it on hats and t-shirts, read about it on the cover of every technical magazine on the planet, and hear it on the radio or the occasional Gregorian chant album .... well, maybe it hasn't gone quite that far yet, but don't be surprised if it does. XML, the Extensible Markup Language, has seemed to take over every aspect of technical life, particularly in the Java community. An application is no longer considered an enterprise-level product if XML isn't being used somewhere. Legacy systems are being accessed at a rate never before seen, and companies are saving millions and even billions of dollars on system integration, all because of three little letters. Java developers wake up with fever sweats wondering how they are going to absorb yet another technology, and the task seems even more daunting when embarked upon; the road to XML mastery is lined with acronyms: XML, XSL, XPath, RDF, XML Schema, DTD, PI, XSLT, XSP, JAXP, SAX, DOM, and more. And there isn't a development manager in the world that doesn't want their team learning about XML today!
When XML became a formal specification at the World Wide Web Consortium in early 1998, relatively few were running in the streets claiming that the biggest thing since Java itself (arguably bigger!) had just made its way onto the technology stage. Barely two years later, XML and a barrage of related technologies for manipulating and constraining XML have become the mainstay of data representation for Java systems. XML promises to bring to a data format what Java brought to a programming language: complete portability. In fact, it is only with XML that the promise of Java is realized;Java's portability has been seriously compromised as proprietary data formats have been used for years, enabling a system to run on multiple systems, but not across businesses in a standardized way. XML promises to fill this gap in complete interoperability for Java programs by removing these proprietary data formats and allowing systems to communicate using a standard means of data representation. This books is a book about XML, but is geared specifically at Java developers. While both XML and Java are powerful tools in their own right, it is their marriage that this book is concerned with, and where the true power of XML lies. We will cover the various XML vocabularies, look at creating, constraining, and transforming XML, and examine all of the APIs for handling XML from Java code. Additionally, we cover the hot topics that have made XML such a popular solution for dynamic content, messaging, e-business, and data stores. Through it all, we take a very narrow view: that of the developer who has to put these tools to work. A candid look at the tools XML provides is taken, and if something is not useful (even if it is popular!) we will address it and move on. If a particular facet of XML is a hidden gem, we will extract the value of the item and put it to use. This book is meant to serve as a handbook to help you, and is neither a reference nor a book geared towards marketing XML.
Finally, the back half of this book is filled with working, practical code. Although available for download, the purpose of this code is to walk you through creating several XML applications, and you are encouraged to follow along with the examples rather than skimming the code. We introduce a new API for manipulating XML from Java as well, and complete coverage and examples are included. This book is for you, the Java developer, and is about the real world, not a theoretical or fanciful flight through what is "cool" in the industry; We abandon buzz-words when possible, and define them clearly when not. All of the code and concepts within this book has been entered by hand into an editor, prodded and tested, and are intended to aid you in your road to mastering Java and XML.
Organization
This book is structured in a very particular way: the first half of the book (Chapters 1 through 7) focus on getting you grounded in XML and the core Java APIs for handling XML. Although these chapters are not glamorous, they should be read through in order, and at least skimmed even if you are familiar with XML. We cover the basics, from creating XML to transforming it. Chapter 8 serves as a halfway point in the book, covering an exciting new API for handling XML within Java, JDOM. This chapter is a must-read, as the API is being publicly released as this book goes to production, and this is the reference for JDOM 1.0 (as I wrote the API with Jason Hunter specifically for solving problems in using Java and XML!). The remainder of the book, Chapters 9 through 14, focus on specific XML topics that continually are brought up at conferences and tutorials I am involved with, and seek to get you neck-deep in using XML in your applications, now! Finally, there are two appendices to wrap up the book. The summary of this content is as follows:
Chapter 1, Introduction
We will look at what all the hype is about, examine the XML alphabet soup, and spend time discussing why XML is so important to the present and future of enterprise development.
Chapter 2, Creating XML
We start looking at XML by building an XML document from the ground up. Examination of the major XML constructs, such as elements, attributes, entities, and processing instructions is included.
Chapter 3, Parsing XML
The Simple API for XML (SAX), our first Java API for handling XML, is introduced and covered in this chapter. The parsing lifecycle is detailed, and the events that can be caught by SAX and used by developers are demonstrated.
Chapter 4, Constraining XML
In this chapter we look at the two ways to impose constraints on XML documents, Document Type Definitions and XML Schema. We will dissect the differences and analyze when one should be used over the other.
Chapter 5, Validating XML
Complementing Chapter 4, this looks at how to use the SAX skills previously learned to enforce validation constraints, as well as how to react when constraints are not met by XML documents.
Chapter 6, Transforming XML
In this chapter the Extensible Stylesheet Language and the other critical components for transforming XML from one format into another are introduced. We cover the various methods available for converting XML into other formats, and look at using formatting objects to convert XML into binary formats.
Chapter 7, Traversing XML
Continuing to look at transforming XML documents, we discuss XSL transformation processors and how they can be used to convert XML into other formats. We also examine the Document Object Model (DOM) and how it can be used for handling XML data.
Chapter 8, JDOM
We begin by looking at the Java API for XML Parsing (JAXP), and discuss the importance of vendor-independence when using XML. I then introduce the JDOM API, discuss the motivation behind its development, and detail its use, comparing it to SAX and DOM.
Chapter 9, Web-Publishing Frameworks
This chapter looks at what a web-publishing framework is, why it matters to you, and how to choose a good one. We then cover the Apache Cocoon frame work, taking an in-depth look at its feature set and how it can be used to server highly-dynamic content over the Web.
Chapter 10, XML-RPC
In this chapter we cover Remote Procedure Calls (RPC), its relevance in distributed computing as compared to RMI, and how XML makes RPC a viable solution for some problems. We then look at using XML-RPC Java libraries and building XML-RPC clients and servers.
Chapter 11, XML for Configurations
In this chapter we look at using configuration data in an XML format, and why that format is so important to cross-platform applications, particularly as it relates to distributed systems.
Chapter 12, Creating XML with Java
Although covered in part in other chapters, here we look at the process of generating and mutating XML from Java, how to perform these modifications from server-side components such as Java servlets, and outline concerns when mutating XML.
Chapter 13, Business-to-Business
This chapter details a "case-study" of creating inter- and intra-business communication channels using XML as a portable data format. Using multiple languages, we build several application components for different companies that all interact with each other using XML.
Chapter 14, XML Schema
We revisit XML Schema here, looking at why the XML Schema specification has garnered so much attention, how reality measures up to the promise of the XML Schema concept, and examining why Java and XML Schema are such complementary technologies.
Appendix A, API Reference
This details all the classes, interfaces, and methods available for use in the SAX, DOM, JAXP, and JDOM APIs.
Appendix B, SAX 2.0 Features and Properties
This details the features and properties available to SAX 2.0 parser implementations.