This article is duplicated with permission by SIGS publications. The original publish date is March 1998. Some changes were made to this electronic version by SIGS publications.

By David Orchard

Java and XML, Objects and Documents: the Twain shall meet

In 1996 and early 1997, many developers and especially object-oriented developers believed that the future of the complex web software was with Java. Java uber-alles hasnít come to pass, as Java is now seen as a great server language but not quite delivering on the ubiquitous web client language, mostly due to the lack of standard browser support. Starting in mid 1997, and continuing into 1998, another language has emerged as the heir apparent to HTML. That language is XML, the eXtensible Markup Language. Again, the web heavyweights have weighed in with their views and products.

Java and XML, while appearing quite different, are actually striking similar. They are the harbingers of the convergence of computing, content and communications. The combination will become a standard for web development. Indeed, the combination of Java, HTTP and XML will remove many of the differences between objects and documents, giving rise to the statement that "documents are objects". It is my contention that most web projects will settle on HTML/XML as the document/object interchange format, URLs as the object naming standard, Java as the server and often-used client language, and XML Web servers as the Object Servers.

To reach this conclusion, this article will compare and contrast the two types of development - document and object-oriented. The first order of business will be to quickly describe the relevant qualities of Java and XML, followed by the development process used in each. The key aspects of definition, extensibility, relationships, reflection and distribution will be compared. Finally, I'll detail a number of ideas on where XML and Java will converge.



For most object-oriented developers, Java is the de-facto standard for software development. It is fully object-oriented by virtue of its strong typing, properties, methods, interface inheritance, behavior inheritance and polymorphism. These are combined into the three tenets of object orientation: encapsulation, extension through inheritance and polymorphism. It is also moderately reflexive, meaning that Java objects can reflect on the semantic meaning of other Java objects.

The Web is founded on the trio of HTML, HTTP and URL. These are moderately supported in Java through the IO and Net libraries. Java has added more distribution protocols, allowing easier communication across machine boundaries. The distribution comes in the form of RMI in Java 1.1, CORBA in Java 1.2 and DCOM in the Microsoft VM. Java has many other attributes, which make it exciting Ė the virtual machine, rich standard class libraries, security mechanisms.



XML is derived from the Standardized Generalized Markup Language (SGML), which has a famous offspring, HTML. XML is a simplified version of SGML. They are both meta-languages, which means they are used to create languages or vocabularies. SGML was created to solve the problem of single-sourcing extensible textual content. A classic example of the single source document is product documentation, which must be available online as well as in hardcopy form. Thus SGML became very cumbersome in order to deal with the complexities of all the different output formats and integration with other content types.

The XML 1.0 specification is now a recommended standard by the World-Wide Web Consortium (W3C). The two battling browser titans have both promised to support XML. Microsoft already uses XML to define the Channel Definition Format (CDF) for it's push media, and they have been working extensively on the Microsoft XML Parser.

XML (and SGML) documents are described in a Document Type Definition (DTD). The DTD specifies the allowed entities and structure. A sample DTD fragment is:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE greeting [

<!ELEMENT greeting (#PCDATA)>



HTML is a vocabulary of SGML, and each of the various HTML variants has a fixed Document Type Definition. The HTML standards wars have all been about what are valid additions to the HTML DTD. Browsers then understand the various HTML DTDs and know how to render the various entities.

XML is exciting because developers can easily create their own DTDs, and write their own applications that grok XML documents and DTDs. So applications can be written - in Java, JavaScript, Perl, Squeak or the latest language - to do something interesting with the document content, such as rendering, filtering, sorting, or joining.

An XML document that is an instance of the previous DTD could be:

<greeting>Hello World!</greeting>

The DTD is actually optional, so we can expect that a great number of XML documents will be created without DTDs. XML allows either strong or weak typing of documents to a particular DTD. This is referred to as validity, and validity is optional for XML documents. XML documents must be well formed, which means they follow the XML syntax. Web browsers do not force HTML documents to be well formed as HTML is concerned about presentation, not content. As XML is an information format, the information must be well formed.

A sample document fragment without a DTD is:

<employee MONTH=12 YEAR=1997>

The advantages of XML are three fold:





Object-oriented development typically follows the iterative process of requirements gathering, analysis, design, implementation, test and ship. The analysis and design phase is usually an extensive modeling exercise, using tools such as Rational Rose and formats like UML, and producing multiple models. Often, the models are created from scratch. Then developers engage in a "death-march" coding exercise to convert the design into running code.

CORBA, Java, C++, SQL, COM, and other languages or specifications are the staples of the object developer. From initial project startup to deployment is usually a year, and more often than not, much longer.



Document or content development usually follows a somewhat different development path. The time to develop content for the web is much faster than software development typically Ė this has led to the term "web-years". The content we are most interested in is web content, which is either created from scratch or by publishing an existing document.

The typical company Human Resources manual is put online by taking a Word document, publishing it to HTML, then providing a link to it from the company intranet. Diagrams, training videos and employee address books soon followed as more types of content found themselves presented for usersí consumption. Eventually, organizations realized they could do much more, such as integrating the web pages with more dynamic content stored in a relational database. A bit of Perl scripting, some web templates, a few months of a developerís time, and an interactive application is online.

A document-indexing engine is another desirable feature, so a categorization mechanism is created. Textual documents can be categorized automatically by keyword extraction, but non-textual documents must have a human generated metadata specification and classification. As much as Iíd like to get into an extended discussion about the nature of knowledge and information, and how that nature relates to representation in textual, visual and/or audio formats, unfortunately the study of communication, media and knowledge is left as an exercise for the reader. Suffice to say that most of an organizationís formalized information is stored in text files which are easily indexed.

MS Word, audio, video, GIF, and HTML are some of the more common content types. The web content creation effort combines the existing database or document repository with the simple distribution mechanism of the web.

The addition of XML to the web means that content creators will create more semantically meaningful content, applications that combine different XML documents together, and applications that monitor XML documents for semantic content changes.


The twain

Interestingly, object developers are often very critical of the web. Arguably two of the prophets of the distributed object future, Dan Harkey and Rob Orfali, have written many articles and books on the future of the web. In the object developer view, the future of the web is the ObjectWeb, which uses Java and one of the various distributed object technologies, such as CORBA, RMI or COM. HTTP and Web browsers are only useful as transport and container for Java objects. Indeed, they believe that the web is broken, and needs fixing.

I only wish I could create something that was as "broken" as the web. With $8 billion in transactions in 1997, the Web is by no means broken. But the object developerís attitude toward the web is due to its complete chaos. The web makes it easy to create and publish documents, but prior to XML, the web did not have many of the attributes that Object Oriented developers believe in: strong typing of objects, rich relationships, extensibility, structure, and meta-data. As well, the three protocols of the Web are viewed as inadequate for serious applications: URLs are not a sufficiently rich naming system, HTTP is too simple a protocol, and HTML is completely inadequate for application information interchange.

On the other hand, content developers expect to be able to quickly create and publish new content, usually in the form of documents. The world eagerly awaits their content, and they need to continually update it or the web site will wither and perish. Developing well-designed Java apps is seen as unnecessary. Why should an author learn to be a Java developer? Content is King, and creating complicated relationships between content is secondary.

The structure of generic computing development versus content development can be crystallized into Java programming versus HTML authoring. The two camps see the world in very different ways, develop different skills, and give themselves different titles. A Java programmer calls him or herself a guru, a developer, an engineer, a technical lead, a geek, but a title of writer, author, content-creator, multi-media developer, or producer will never grace their business card.

Indeed, the worlds of engineering and authoring have always been far apart - Authors are from Mars and Programmers are from Venus.


Shall meet

But the web is forcing them to co-operate. There always will be differences, but they wonít be as great as in the past. The same way atom-based products, such as manufacturing, have seen the formation of cross-disciplinary teams, so too with bit-based software products.

XML is the latest language for web-based textual content creators. HTML was too restricted, SGML too complicated, RTF too limited, and XML is just right. XML will also be a key interchange format for object-oriented developers. The convergence is happening as a result of a number of key common features. XML is adding complex extension and linking relationships to deal with the traditional content developer.



Having explored Java and the content development process, we now dive into some of the key attributes of Java and Web/XML - extensibility, relationships, reflection, and distribution. For the purposes of this article, extensibility refers to whether an object model supports creation of arbitrary element definitions and includes re-use of existing definitions. Table 1. Provides a comparison.







Document contents



CGI, Java Servlets, *APIs


Bean events


Interface definition

Interfaces, Classes

Document Type Definition

State Inheritance


No - Linking

Interface inheritance



Strongly-typed interfaces





HTTP methods, DOM


RDB, OODB, Files

RDB, OODB, Files



Style Sheets

Human readable objects

No - .class files





Message communication



Composition relationship



Arbitrary relationships




Java provides extension of functionality through the use of class and interface definitions. A Java class defines the properties, methods, events and exceptions provided by a class, as well as any existing interface or class definitions that are extended. Other relationships and cardinalities between classes and objects are possible. So a Java object is defined via classes and interfaces, which may be extensions of other classes and interfaces.

HTML does not allow for extensibility - no additional tags allowed unless you are Netscape or Microsoft. XML opens the door to web extensibility through a number of mechanisms: the arbitrary definition of elements in a document, the definition of valid elements in a document through a DTD, the interface extension by extending a DTD, and extension of other documents using the linking specification (XLink). To compare XML to Java, a DTD is a property-only class, and an XML document is an instance of that class.

Web servers are extremely extensible, as copying a file into a directory implements the GET method of a URL. As well, various APIs and Servlets can augment a web server with arbitrary methods.

One of the first efforts in Java development and analysis is the description of the relationships between objects. Indeed, the strength of object-oriented analysis has been the focus on static relationships, rather than dynamic data flow or state transitions. The relationships typically fall into three types - inheritance, composition, and reference.

Interestingly, XML and HTML are moving towards an area that object developers have focused much effort on: relationships. The original vision of the web was articulated by Vannevar Bush with his hypermedia device the Memex. The Memex allowed a user to create arbitrary trails through documents. The current web has very limited and simplistic relationships between documents, and they are confined to the documents themselves. That is, an HTML document relates to another document through a hyperlink embedded in one of the pages.

Tools such as NetObjects Fusion and Microsoft FrontPage 98 now offer relationship editors, where the static hierarchical relationship between documents is defined outside of an HTML page. Soon we will be able to create the relationships dynamically.

The upcoming XML link specification promises to address many of the link issues. It will add to web documents links that are bi-directional, pointers within a document, link descriptions that exist independently and outside of the documents referred to, aggregation of links, and many other powerful document linking characteristics. Unfortunately, the XML link specification will not be ready for several months.

Reflection refers to the ability of an object to find the interface definition of another object. Reflection allows computation to be deferred to run-time rather than compile-time, where more information may be available. It is a commonly held belief that programs that are reflexive are more adaptable and less prone to errors. Indeed reflection is at the heart of adaptability of programmatic behavior, and adaptability is the single greatest factor in the success or failure of software programs.

Java 1.1 added the reflection library so that a Java object can determine the methods, properties and events of another Java object. This information can be used to dynamically alter program behavior based upon the object being reflected.

The interface specification of an XML document can be obtained by either: parsing the entire document and generating the specification, or parsing the document type specification and retrieving the specification.

Web servers have the capability of returning the definition of a URL named object. HTTP has the HEAD request, which causes a web server to return the section of an HTML document in the HEAD portion of the document. The addition of the XML DTD specification to the document specification means that Web servers already know how to return the interface definition of a URL. Thus object definition Ė meta-data - is already on the Web through the adoption of XML.

Distribution is a final key aspect of the power of XML and Java. The ability of objects to find and use remote objects has led to the development of the distributed object technologies of CORBA, RMI and DCOM. Among other things, these technologies provide interface definition languages, Object Request Brokers, Inter-Orb communication, and a variety of services - naming, security, persistence etcetera. I've said many a time that the decision about the appropriate distributed object technology for a project is often specified far too early as it is really the services offered by the middleware that are important. For simple message transfer between clients and servers, XML over HTTP 1.1 is a very easy and powerful choice. While I do not have the temerity to suggest that CORBA are not valuable, it is clear that object developers should rethink their earlier dismissal of HTTP due to the addition of XML. In fact, I believe that HTTP 1.1 will become the de-facto standard protocol for object transmission and communication, and XML DTDs will become the language-independent interface definition language. You heard it here first... To deal with the inevitable flood of hate-mail from zealots of a particular technology, I should probably provide a DTD that all incoming e-mails must implement :)

It is clear that Java and XML documents are similar in many regards. They both have data associated with objects, interface definitions, roughly similar notions of extension, and are self-describing. Java provides richer relationships and has more expressive behavior semantics. XML has more expressive presentation binding. The combination of the two with a Web server provides a powerful set of features.


Web Servers as Object Servers

Given the ability of XML to be the representation format for any object, imagine XML being the interface definition language for the Web, augmenting HTTP and URLs. At the heart of the web server is really an object server. A web server knows how to execute certain methods - PUT, GET, POST - on objects falling within the URL namespace. The addition of XML means that arbitrarily structured objects may be interchanged between web clients and servers.

There are many wonderful and exciting effects that the convergence of XML and Java has on software development. Some of the more interesting ones are:

Let's take a bit of time to explore some of the convergent areas.

A trivial coding exercise can provide XML as the serialization format for Java. Rather than the cumbersome process of formatting HTML in Java code, servers can simply serialize a Java object into XML and return it to the client in response to a request. Java objects could be streamed to the file system as XML files, and then a Java client could use the Web server to copy the stored object from the server to the client.

Java Servlets are available for all the major web servers. Here again the convergence of Java and the Web is happening. Servlets come in two forms:

A Java client could use the reflection APIs to introspect local Java objects, or the HTTP HEAD to introspect remote URL objects. I hate over-using the term "easy", but again it should be easy to extend the Java RMI and reflection APIs to use XML and HTTP as standards to specify and invoke remote object services. Thus a remote object named "http://myserver/XMLObject" and implemented as an XML document could be introspected to find its properties and the GET method invoked. Or, a Java Servlet could implement the HTTP HEAD method to return a DTD listing the properties and methods supported by the Servlet.



Having seen and investigated many web technologies over the past few years- agents, push, VRML, CORBA, and SGML - I have to say that XML ranks in my top 3 list of key technologies. After seeing Mosaic in 1994 and HotJava in early 1995, XML brings the same sense of imminent and inevitable radical software change. I believe in the convergence because XML is a powerful storage format for objects, DTDs are a powerful object description language, Web servers are widely deployed and extensible object servers and Java is the language of choice for applications and server objects. The worlds of Java and the Web are converging because XML provides the final gateway to bridge Web documents and Java objects.