our assignment: To create a Web site that sings. You need to build from a fountain of information that continually replenishes itself. And you need to perform your magic on Web-page layout created by HTML designers.
There are a couple of ways to do this. One is Enhydra XMLC (eXtensible Markup Language Compiler), an open-source technology whose purpose closely parallels the utility of JavaServer Pages (JSP). Both technologies are designed to simplify the development of dynamically generated Web content, typically in a servlet architecture. The overall approach of each technology is, however, quite different.
JSP extends existing Java Servlet technology through the inclusion of Java code in markup language files, particularly HTML. JSP files are a mixture of markup code and Java code which are compiled into a servlet class. Executing inside a servlet context, the embedded Java code creates dynamic content to be returned by the servlet.
XMLC provides a similar functionality but without inserting Java specific tags or code into markup language files. For each input HTML file, XMLC generates a Java class capable of reproducing the exact markup of the file. The Java class actually contains a Document Object Model (DOM) representation of the Web page. This allows a developer to dynamically alter the page content by manipulating the DOM.
Rather than embed Java directly into the markup language file, the dynamic link between markup code and Java code is accomplished via the DOM. During compilation, XMLC creates convenience methods to facilitate DOM manipulation. In particular, XMLC adds the convenience method getElementXXX() for every standard markup tag that includes an attribute of the form ID="XXX". Having obtained a DOM Element reference, a Java developer may manipulate the element in any DOM consistent manner. Obviously these ID attributes need to be unique within a single markup language file to be meaningfully accessed by the Java code.
Furthermore, since text manipulation is so common for dynamically generated Web pages, XMLC also adds the convenience method setTextYYY(String) for all SPAN tags with an attribute of the form ID="YYY". SPAN tags are standard HTML markup for delineating text content. These convenience methods provide an easy access point for dynamically generating text.
In this article I investigate using XMLC for generating dynamic Web content by developing a very simple Stock Quote page which displays a list of stock prices for a specified customer. The example HTML and Java code is purposely kept simple while still allowing the benefits of XMLC to shine. I do not cover XMLC installation and setup; please refer to the open-source site xmlc.enhydra.org for download and installation instructions.
|