spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / xml / column23

Dynamically generating HTML pages with XMLC

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Compiling HTML Pages

You can download XMLC from the Enhydra Site. Let's put it to work:

The xmlc command is used to run XMLC. It parses an HTML page and normally creates a Java class than contains a DOM representation of that object.

The XMLC compilation process is straight forward, with only a class name, output directory and a HTML file normally required as parameters. For example:

 xmlc -d classes -class sample.Hello hello.html
would generate an XMLC class named sample.HelloHTML from a HTML file hello.html and writes the resulting class file under the directory classes. The HTML page could look like this:
<html><body>
Hi there, the local time is <span id="time">now</span>.
</body></html>

Generated Document Class

The xmlc command compiles the document into a Java class:
public class HelloHTML extends org.enhydra.xml.xmlc.html.HTMLObject
    implements org.w3c.dom.html.HTMLDocument {

    SpanElement getElementTime() {
        return getElementByName("time");
    }

    void setTextTime(String time) {
        ... // DOM code to replace the text in the span tag with 'time'
    }

    ... // more DOM stuff
}
In addition to the standard DOM document access method, the generated class will contain a get method for each element that contains an identifier attribute.

For HTML documents, this is the id attribute, valid for almost all tags. With XML documents, these are all attributes declared to be type ID in the DTD.

The get method will be named in the form getElementIdname. With the first character of the id being shifted to upper case to conform to the Java convention. The return type will be the DOM class that represents the element.

For span tags, a set method is generated for replacing the text inside the span element with the passed in argument.

On to using XMLC generated objects.

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Produced by Michael Claßen
All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/xml/column23/3.html
Created: Nov 05, 2000
Revised: Nov 05, 2000