XML and Java: A potent partnership, Part 2
Learn how to use Java to build applications that handle XML's extensibility
By Todd Sundsted, JavaWorld.com, 07/24/99
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Last month I presented my case for the place of XML in the enterprise (for last month's column, see
Resources). I intentionally tried to look beyond the publishing aspects of XML in order to focus on application integration and data
exchange issues. I demonstrated how easy it is to parse and validate XML using commonly available Java tools, and I compared
those methods to more traditional ad hoc methods.
How-To XML & Java: Read the whole series!
This month, I wish to carry the thread further -- parsing and validating are fine as far as they go, but they don't go very
far. The problem at hand typically involves doing something with the parsed information. But what if you don't understand
the tags used to generate the information? Come walk with me a bit farther along the border between Java and XML, and I'll
show you how to use Java to solve that problem, too.
XML tags: What to do?
Let's proceed straight to the heart of the matter. The feature of XML we need to address is its ability to define new tags.
A tag in XML says something about the meaning of the content (and about the other tags) it associates with. Because the set
of tags in XML is open (unlike HTML, where the set is closed), it's impossible to build an application that handles the entire
tag set right out of the box. This introduces a bit of uncertainty into the process. What exactly do you do with tags you
don't understand?
- Applications can ignore novel tags. This was the approach typically taken by browser vendors during the height of the browser wars. Leading browser vendors merrily
defined new tags with each release of their product, and each browser distribution quietly ignored those tags it didn't understand.
This approach is safe but not very satisfactory.
- Organizations can standardize on a set of tags. This approach cleverly sidesteps the entire problem. You define a set of standard tags and a document type definition (DTD),
and then reject any XML that doesn't fit the mold. This is actually the right solution for many problems. Sales orders, for
example, fit a well-defined pattern. Nothing is gained by allowing e-commerce partners to define new tags (at least without
constraint -- the case could be made for the applicability of certain well-constrained tag definitions, such as macros). Unfortunately,
not all applications -- XML browsers, for example -- fit within this box.
- Applications can try to figure out what to do with novel tags. Browsers and content-presentation tools as well as other general-purpose XML tools must behave correctly in the presence
of novel but valid tags. There are several ways to solve this problem. The Extensible Stylesheet Language (XSL) is one such
attempt. XSL provides a translation toolkit, which allows you to define a mapping or translation from a tag set you don't
understand to a tag set you do understand (for example, XML to HTML). This solution, however, has its own limitations.
- You can build a new framework. While each of the solutions above has its place, we'll explore another solution altogether. Our solution calls for enabling
the browser or XML tool to look for and download code designed to handle the novel tags and then integrate that code into
the application. To do this, we'll build a new framework.
Before we can get down to the business of building our solution, we need to understand a little more about XML. In particular,
we need to understand how to manipulate XML within an application. We need to understand the Document Object Model (DOM).
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone