Creating Dynamic Content with Enhydra XMLC (cont'd)

Generating Dynamic Text Content

The first version of StockQuotes.html sets the stage for adding dynamically generated text for a customer's name and the current time. The following HTML markup contains two SPAN tags with ID attributes "custName" and "reportTime." The XMLC-generated Java class for this markup contains the convenience methods

setTextCustName(String)
and
setTextReportTime(String)
that provide the easy access points for setting the Web page content.

<! -- StockQuotes.html, Version 1 -->
<HTML>
<TITLE>
  Stock Quotes
</TITLE>
<BODY BGCOLOR="#D0D0D0">
<H2 align=CENTER>
  Welcome < span id="custName"> Customer Name< /span>
</H2>
<H3>
  Stock quotes for < span id="reportTime"> current time< /span>:
</H3>
</BODY>
</HTML>

The following command uses XMLC to actually generate the Java class for the above markup.

  xmlc StockQuotes.html

XMLC reads the input file "StockQuotes.html" and generates a Java class file named "StockQuotes.class." The command line argument

'-keep'
may be used to instruct XMLC to keep an intermediary Java source file, "StockQuotes.java," which the compiler deletes by default. When first learning XMLC, however, poking around in that file is quite instructive, but not strictly necessary.

 
Figure 1 | Customer "Elmer Fudd"

Now that I have the class "StockQuotes," I create DynStockQuotes to actually perform Web page manipulation utilizing that class. Typically, the code in "DynStockQuotes" (sans the main method) would be placed in a file operating within a servlet architecture. I'm using the code free of servlets for ease of demonstration. The method

DynStockQuotes.main
creates a dynamic StockQuotes page and prints the generated HTML code for the specified customer name to the standard output stream. The image to the right shows the resulting Web page for customer "Elmer Fudd."

The setting of dynamic content in class DynStockQuotes occurs inside the method

createHtml(String): 

  StockQuotes stockQuotes = new StockQuotes();
  stockQuotes.setTextCustName( custName );
  stockQuotes.setTextReportTime( new Date().toString() );
  return stockQuotes.toDocument();

A newly created StockQuotes object is used to set the text for customer name and report time through convenience methods provided by XMLC. The

toDocument()
method renders the StockQuotes DOM into HTML as a String.

That's all it takes to generate dynamic content! XMLC has done all the dirty work. With just a few lines of code, I use an XMLC generated class to alter the Web page content. And best of all, my HTML file doesn't contain any Java code or non-standard HTML markup.


Introduction

Generating Dynamic Table Content

In this Article
Introduction Generating Dynamic Table Content
Generating Dynamic Text Content Adding Mock-up Content








FEATURE SOFTWARE:
dtSearch Web
Add power searching to your web site.
Buy Now!

Encrypt It
Encrypt and Decrypt Data, Passwords and Files within your application.
Buy Now!

FEATURE BOOK:
PointBase Mobile Edition
Enable local data access for mobile users.
Buy Now!
Enhydra.org

DevX Java 2 eLearning

DevX Java Zone

Product Review of the Week
Rational Suite 2001

Site of the Week

Book Review of the Week
Object-Oriented Implementation of Numerical Methods

Tip of the Day
Use Math.PI and Math.E for Scientific Calculations

Download of the Week
Ebitec JMS Mail Bridge





 
Sponsored Links

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers

Copyright Information/Privacy Statement