Dynamically generating HTML pages with XMLC (4/4) - exploring XML
Dynamically generating HTML pages with XMLC
Using XMLC Generated Objects
Generated XMLC Objects are manipulated using the DOM API as well as element access methods generated by XMLC. Dynamic data is set in the DOM object tree and finally an HTML page is generated from that tree:public class Hello implements HttpPresentation { public void run(HttpPresentationComms comms) { HelloHTML page = new HelloHTML(); String now = (new java.util.Date()).toString(); page.setTextTime(now); comms.response.writeHTML(page); } }On execution of the
run()
method this will send back a page saying
something like:Hi there, the local time is Sun Nov 5 14:25:00 CET 2000.
Name and Class Constants
String constants will be generated for each element name and class name. The use of string constants when calling DOM routines to locate elements ensures that a valid element is specified.For an element:
<INPUT NAME="myName" CLASS="class1 class2">The constants
public static final String NAME_myName; public static final String CLASS_class1; public static final String CLASS_class2;
These constants are used when accessing the DOM, for example:
NodeList elements = htmlObj.getElementsByName(htmlObj.NAME_myName);
Conclusion
XMLC is an interesting case of moving a well-known concept from one domain to another, in this case from browsers to servers. It is used on at least one public Web site AnywhereYouGo, a site on WAP and Bluetooth. Many more Intranet projects are on the way as you can see from the Enhydra mailing list archive.
The described method works for all XML document types, including Wireless Markup Language (WML). Using this approach makes it easy to serve different clients the same kind of dynamic content by simply replacing the HTML resources with WML pages. Why not give it a try on your Java-enabled Web Server?
Acknowledgements
This article contains excerpts of the XMLC documentation that ships with XMLC and Enhydra, © 2000 Lutris Technologies, Inc.
Produced by Michael Claßen
All Rights Reserved. Legal Notices.
URL: https://www.webreference.com/xml/column23/4.html
Created: Nov 05, 2000
Revised: Nov 05, 2000