Generating HTML from both XML and relational input data

exercise No. 36

Q:

We want to extend the transformation Figure 771, “Transforming an XML document instance to HTML by a XSL style sheet. ” by reading price information from a RDBMS. Consider the following schema:

CREATE TABLE Product(
  orderNo CHAR(10) NOT NULL PRIMARY KEY
 ,price DECIMAL (9,2) NOT NULL
);

INSERT INTO Product VALUES('x-223', 330.20);
INSERT INTO Product VALUES('w-124', 110.40);

Adding prices to your final HTML output may be implemented the following way:

You may start by implementing and testing the following methods of a RDBMS interfacing class using JDBC:

public class DbAccess {

   /** Open a connection to a RDBMS.
    * @param jdbcUrl The database server's address
    * @param userName The user's name
    * @param password The user's password
    */
   public void connect(final String jdbcUrl,
         final String userName, final String password) {
    ...
   }
   /** Read the price from the RDBMS for a given article number. In a "real"
    *  application we'd use an integer type rather than a string.
    * @param articleNumber
    *   The number of the article for which we search pricing information.
    * @return
    *   The price if available, else an error message.
    */
   public String readPrice(final String articleNumber) {
      ...
   }
   /**
    * Close the database connection.
    */
   public void close() {
      ...
      }
   }
}

Tip

You may want to write a small testbed assuring RDBMS access functionality working properly prior to integrating it into your DOM application producing HTML output.

Then extend Figure 771, “Transforming an XML document instance to HTML by a XSL style sheet. ” by introducing a new method addPrices(final Document catalog) which adds prices to the DOM tree accordingly.

A:

The additional functionality on top of Figure 771, “Transforming an XML document instance to HTML by a XSL style sheet. ” is represented by a method de.hdm_stuttgart.mi.sda1.rdbmsxml2html.XmlRdbms2Html.addPrices(). This method modifies the DOM input tree prior to applying the XSL by inserting data received from the RDBMS: