Newsletter sign-up
View all newsletters

Sign up for our Enterprise Java Newsletter

Enterprise Java

XML JavaBeans, Part 1

Make JavaBeans mobile and interoperable with XML

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
HTML (Hypertext Markup Language) currently is the document format of the World Wide Web. Lately, though, there's been a lot of noise about XML (Extensible Markup Language), which allows, among other things, the ability to define new markup tags (the bits between <angle brackets>), or even whole new markup languages. Some pundits even claim that XML may supplant HTML as the dominant information format on the Web.

Read the whole "XML JavaBeans" series:



For some, XML seems one of those ideas that, while exciting at first, isn't entirely useable in practice. How would a developer use XML in a real life system? What good is the ability to define custom tags if no browsers understand them? In this month's column, we'll look at a possible application of XML -- namely, using it as a serialization format for JavaBeans.

First, you'll read a quick rundown of what XML is and why so many people are so excited about it. Next, you'll hear about the World Wide Web Consortium's (W3C's) Document Object Model, the proposed standard for representing documents as data structures. As an example of processing a document as a data structure, we'll describe a very small custom markup language, and then implement a class that reads an XML file and transforms it into a JavaBean.

Please note that the primary purpose of this article is to provide an example of XML in use. While it is not an introduction to XML for the complete novice, this article should be comprehensible with just a bit of preparatory reading (see the introductory articles listed in the Resources section.)

What's wrong with HTML, anyway?

There's a great deal of introductory material on the Web about XML, so we're going to go over XML basics pretty quickly. Let's start by discussing why XML is necessary in the first place.

It's easy to make the argument that HTML enabled the explosion of the Web. Among the many strengths that have made HTML the dominant format for Web documents are the following:

  • HTML is very easy to learn and use. Practically anyone with a pulse can learn to write HTML. Reading HTML in a Web browser is so simple and intuitive that just about everyone grasps it instantly.

  • Logical layout makes HTML documents portable. HTML markup describes to a browser what roles various pieces of text play in a document (title, list element, and so on,) and the browser is free to decide how (or if) to display them. This provides a great deal of device independence.

  • Hypertext forms webs of knowledge. One of the most useful features of HTML for many applications is the ability to make information "come alive" and refer to other information.

  • HTML forms a framework for composite documents. The addition of applets and other sorts of "active" page elements provides immense creative control to developers on the Web "platform."


Despite these and the many other strengths that make HTML so useful and, well, cool, it has some serious drawbacks that are rapidly becoming obstacles to using it in serious data applications:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (1)
Login
Forgot your account info?

Java BeansBy Anonymous on February 3, 2009, 2:39 amHi, This is a good article with lots of information. I had a situation where we are using a (user defined) Java class for communication between client and server. Bean.java...

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • For IBM's Bean Markup Language (BML), see http://www.alphaWorks.ibm.com/formula
  • One of the better "one-stop shopping" sources for XML information is at XML.com. It has links to just about everything in the XML world. One of the more interesting things at this site is, believe it or not, the commentary on XML technology. See http://www.xml.com
  • A current version of the XML FAQ by Peter Flynn, et al., appears at the following site. This is the version of the FAQ recommended by the W3C http://www.ucc.ie/xml/
  • The parser from IBM's xml4j package is available free for noncommercial use. It's even free for commercial use, but be sure to read the license agreement first http://www.alphaWorks.ibm.com/formula/XML
  • In a note unrelated to JavaBeans, but still too cool for words, check out Jikes, IBM's new open source java compiler! Find out about it at the alphaWorks site http://www.alphaWorks.ibm.com/formula/JikesOS
  • For IBM's Bean Markup Language (BML), see http://www.alphaWorks.ibm.com/formula/BML
  • If you're interested in the fine details of the current Document Object Model (Level 1) Specification, you can find it at the W3C's Web site http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html
  • Microsoft has a good set of tutorials on XML http://www.microsoft.com/xml/tutorial/default.asp
  • Microsoft also offers a whole XML "workshop" area. Don't try to access the workshop in Netscape, thoughthe table of contents doesn't work! These documents are free training, and are well-written (though the examples don't always work, even in IE5beta.) Just don't be fooled into thinking that everything there is open standard. Some of the tutorials and many of the articles are about Microsoft-only technology that won't work with all browsers or platforms. http://www.microsoft.com/xml/default.asp
  • Sun's "Java Project X -- Java Services for XML Technology" Web page features a FAQ on Sun's set of core XML-enabling services written completely in the Java (which you can download), as well as an interview with Dave Brownell, designer of Sun's Java Project X, on XML and Java Technology. http://java.sun.com/products/javaprojectx/
  • The source code for this article is available for download in Unix tar format http://www.javaworld.com/jw-02-1999/beans/XMLBeans.tar
  • It's also available in zip format http://www.javaworld.com/jw-02-1999/beans/XMLBeans.zip
  • You can also download a jar file with the class files, ready to run, from http://www.javaworld.com/jw-02-1999/beans/XMLBeans.jar