Consortium    Solutions    Middleware    Forge    MyObjectWeb 
ObjectWeb Consortium

Advanced - Powered by Google

Enhydra XMLC

Project links
About XMLC
Mailing Lists

Developers' Corner
CVS Repository
ObjectWeb Forge Site

Who We Are
Getting Involved

Commercial Vendors

[ Enhydra XMLC: Open Source Java/XML Presentation Compiler ]

Enhydra XMLC Presentation

by Mark Diekhans

This is a converted slide presentation that introduces key elements of Enhydra XMLC as presented by Mark Diekhans, the lead developer of Enhydra XMLC.


XMLC - An Introduction

back to top

XMLC, like Enhydra Jolt, is used to create presentation objects. An application can use both tools (or write the Java by hand), depending on the needs of the particular presentation object.

XMLC will compile HTML pages, resulting in Java classes. These classes, using DOM, represent the HTML content in Java, and allow programatic manipulation of the HTML. Whereas Jolt outputs presentation objects directly, XMLC outputs Java-representations of the HTML files, which are then used by engineers who are writing the presentation objects by hand. Therefore XMLC is not as automatic as Enhydra Jolt, but it allows for more direct control over the HTML at runtime. For large complex projects we have found that the extra work up front is worth it. But for strightforward dynamic HTML situations we still use Enhydra Jolt.

XMLC is:

  • New technology for generating dynamic HTML and XML content
    • An alternative to Enhydra Jolt, JSP, and other first generation embedded language approaches.
    • HTML/XML files are not hand edited by developer
    • Document is manipulate in a object-orient manner
    • Flow of control is clearly separated from content

  • Converts XML and HTML documents into Java classes (XMLC Object)
    that can reproduce the document.

  • Generated XMLC Object is a resource in generating dynamic XML and HTML
    • Enhydra presentation objects
    • Generic Servlets
    • Generators of static HTML pages
    • Applets and applications


back to top

  • Java embedded in HTML (Jolt, JSP)
    • Works well for simple, hand-coded HTML
    • However it doesn't scale to sophisticated HTML pages developed with design programs

  • HTML pages generated with design programs
    • Are difficult to edit to add dynamic features
    • Once modified to add dynamic features, they are difficult to modify with the design programs
      • Must be maintained by hand
    • The edit pages are no longer suitable as a story board
  • Non-standard APIs are an added burden for developers and customers
    • XMLC is built on the DOM (Document Object Model) with only a small number of additional methods
    • Leverage DOM documentation and books
    • Existing Java classes that operate on DOM will work with XMLC Objects


The Document Object Model (DOM)

back to top

  • A World Wide Web Consortium recommendation (standard)
  • A language-independent object model for representing XML/HTML
  • A set of language-specific interfaces that implement the DOM
    • APIs for creating and manipulating XML documents.
  • Consists of a set of general objects for all XML
    • Developer defines a specific set of Element classes for a particular application of XML
    • Standard defines a set of objects for HTML
  • A set of Java interfaces and support objects for DOM are provided by W3C
    • W3C does not provide implementations


DOM Example

back to top

            <TD>Shady Grove</TD> 
            <TD>Over the River, Charlie</TD>

Java DOM

back to top

  • org.w3c.dom - Generic XML interfaces
    • Node - Interface for all DOM tree nodes
      • Contains children and parent links
      • Provides methods for manipulating the tree
    • Document - Root of tree
      • Provides factory methods for other DOM classes.
      • toString() returns the document
    • Element - Interface for XML tag classes
      • Implements Node
      • Specific XML applications define implementations
    • Text - Nodes that contain the document text
      XMLCUtil.getFirstText() - get Text node to modify


Java DOM and HTML

back to top

  • org.w3c.dom.html - HTML-specific interfaces
    • HTMLDocument - root of the HTML hierarchy, holds the entire content.
    • HTMLHeadElement - document head information.
    • HTMLBodyElement - document body.
    • HTMLParagraphElement - paragraphs.
    • HTMLAnchorElement - anchor element.

XMLC Generated Objects

back to top

  • Compiles an XML or HTML page into a class that can reproduce the page:
  • All generated objects:
    • Extend com.lutris.xml.xmlc.XMLObject
    • Implement org.w3.dom.Document
  • Generated HTML objects:
    • Extend com.lutris.xml.xmlc.HTMLObject
    • Implement org.w3.dom.html.HTMLDocument

  • Instantiating the generated class results in a DOM representation of the original object
  • Full DOM tree is available for manipulating the XML/HTML document
    • Add and delete Element objects.
    • Modify Text objects
    • Libraries of common functions can be developed.

  • Elements that are to be manipulated can be identified using the ID attribute
    • The id must be globally unique within the page
    • For all elements with an ID attribute, XMLC generates an access method for the tag
    • Named in the form getElementIdName
    • Returns the specific class for the attribute
  • Example
    The tag: <table id=fred>
    Generates: public HTMLTable getElementFred();

  • IDs are agreed upon by the HTML designer and programmer
  • Access method allows the structure of the document to change without affecting the code (in many case)
  • To identify a text string within a larger text block or independent of other tags, use <span>.

    <p>Hello my name is <span Id=name>ah, Clem</span></p>

  • When constructing tables
    • A table filled in with dummy data for story board serves as prototype for dynamic table
    • A data row is copied and used as a template
    • Other rows deleted
    • Template row cloned and reinserted into the table
    • A table creation class will be provided to make this easier

  • XMLC can do compile-time replacement of URL references in the page
  • Allows static HTML pages to function as a prototype page.
  • Replace links to static pages with links to presentation objects
    ../checkout/CheckOut.html => ../checkout/CheckOut.po
  • XMLC can output a static page with URLs mapped without generating a class
    • Useful for pages with no dynamic content that reference static pages.

XMLC Compiler Features

back to top

  • Print information about the page or generated DOM tree
  • User-defined Element objects can be used in place of the standard DOM Objects
    • Must still implement the interface for the tag
    • An interfaces that a generated XMLObject implement maybe specified
    • Allow operations on classes that share a set of IDs

Using XMLC

back to top

  • Flow

  • Work with graphics designer on the high-level design and structure:
    • Functional packages
      • Does not have to be an exact mapping to Java packages, however it's useful
  • Dynamic content of pages
    • Type of data
      • Table, Form
      • Text (<SPAN> elements)
    • Agree on element Ids
  • Evolves from initial story board
    • Still functions as a story board


XMLC Command

back to top

  • xmlc [options] [optfile.xmlc ...] src.ext
  • Options maybe on command line or in options file (currently Lutris Config format)
    Common options:
    • -class classname - Fully qualified class name for the generated class.
      -keep - Keep the generate Java source, do not delete it.
      -nocompile - Don't compile the generate Java file.
      -info - Print useful information about the page object, such as ids and URLs.
      -dump - Dump out the DOM tree for the page.
      -verbose - Print information about the compiler process
      parseinfo - Print detailed information about the page parsing.
      -html:frameset - A HTML frameset is being compiled.
  • Options passed to javac
    • -g


Simple XMLC Example

back to top

  • Hello.html, compiled to HelloHTML.class
    <TITLE>Hello World</TITLE>
    <H1>Hello World</H1>
    <P>Hello, my name is <SPAN ID="name">ah, Clem</SPAN>.
    <P>Today's date is <SPAN ID="date">Oct 6, 2001</SPAN>.
  • DOM hierarchy for Hello.html
        HTMLHtmlElement: html
            HTMLHeadElement: head
                HTMLTitleElement: title
                    Text: text="Hello World"
            HTMLBodyElement: body
                HTMLHeadingElement: h1
                    Text: text="Hello World"
                    Text: text="Hello, my name is" 
                    HTMLElement: span: id='name'
                        Text: text="ah, Clem"
                    Text: text="."
                HTMLParagraphElement: p
                    Text: text="Today's date is "
                    HTMLElement: span: id='date'
                        Text: text="Oct 6, 2001"
                    Text: text="."
    public class Hello implements HttpPresentation {
        public void run(HttpPresentationComms comms) {
            HelloHTML htmlObj = new HelloHTML(); 


back to top

  • To use XMLC with non-HTML XML applications
  • Can access as generic DOM objects.
  • Develop specific Element classes for application
    • Also must define a class used by XMLC in parsing and compiling the document
    • Loaded dynamically by XMLC

Copyright © 1999-2004, ObjectWeb Consortium | contact | webmaster | Last modified at 01/23/04 11:18:35 is sponsored by the ObjectWeb Consortium and Together Teamlösungen GmbH.