B2B with XML

Exchange Rate Provider Builds XML Documents from Database Data

August 2000
Oracle8i

The Exchange Rate Provider (ERP) module keeps track of exchange rates for international currencies. Periodically, it notifies the Hotel Reservation System (HRS) about rate changes by sending an XML document via FTP. Then the HRS adminstrator can use the HRS Administrator interface to parse the XML document and update local tables with the new data. The XML and DTD files are shown below.


Note: This sample app doesn't actually implement the ERP module. Instead, you can simulate its behavior by editing xmla2a\a2afiles\xmlfiles\Exchange.xml.


Exchange.XML

<?xml version="1.0" standalone="no"?>
<!DOCTYPE Exchange SYSTEM "Exchange.dtd">
<Exchange>
<Exchange_Rates>
<Home_Country>USD</Home_Country>
<New_Country>GBP</New_Country>
<Rate>.6334</Rate>
</Exchange_Rates>
<Exchange_Rates>
<Home_Country>USD</Home_Country>
<New_Country>ESP</New_Country>
<Rate>172.54</Rate>
</Exchange_Rates>
<Exchange_Rates>
<Home_Country>USD</Home_Country>
<New_Country>FRF</New_Country>
<Rate>6.8019</Rate>
</Exchange_Rates>
</Exchange>

Exchange.DTD

<!ELEMENT Exchange       (Exchange_Rates)*>
<!ELEMENT Exchange_Rates (Home_Country, New_Country,Rate)>
<!ELEMENT Home_Country (#PCDATA)>
<!ELEMENT New_Country (#PCDATA)>
<!ELEMENT Rate (#PCDATA)>

The following code comes from xmla2a.hrs.HRSServlet.updateExchangeRate. It reads data from each node of Exchange.xml to get the exchange rate for each currency. Then it updates the EXCHANGE_RATES table.

public class HRSServlet extends HttpServlet {
  ... 
  // Path of the XML file. This file will be transferred (Assumed to be FTP'ed)
  // by the ERP (Exchange Rate Provider) application.

  final String m_xmlFileName = ConnectionParams.s_pathOfFile + "xmlfiles/Exchange.xml";

  ...

  public  void  updateExchangeRate (String p_user, HttpServletResponse p_res ){
    try {
      // Parse the XML document.
      XMLDocument l_userDoc = m_XMLHandler.parseXMLDocument(m_xmlFileName);

      PreparedStatement l_IDStmt = m_connection.prepareStatement(
         "select id, name from countries where currency=?");

      PreparedStatement l_updateStmt = m_connection.prepareStatement(

        "update exchange_rates set rate=? where home_con_id=? and new_con_id=?");

      Node l_docRoot = l_userDoc.getLastChild();

      // Get the Exchange Rate information from the XML document.
      NodeList l_exchangeRates = l_userDoc.getElementsByTagName("Exchange_Rates");

      String l_message = null;
      Vector l_table = new Vector();  // Vector for sending the updated result.
      for (int i = 0; i < l_exchangeRates.getLength(); i ++) {
        Vector l_row = new Vector();


          NodeList l_exRate = l_exchangeRates.item(i).getChildNodes();
          NodeList l_Rate1 = l_exRate.item(1).getChildNodes();

          String l_homeId=l_exRate.item(0).getChildNodes().item(0).getNodeValue();
          String l_newId=l_exRate.item(1).getChildNodes().item(0).getNodeValue();
          String l_Rate=l_exRate.item(2).getChildNodes().item(0).getNodeValue();

          // Bind currency value to column
          l_IDStmt.setString(1, l_newId);

          ResultSet l_IDRS = l_IDStmt.executeQuery();

          if (l_IDRS.next()) {

            int l_newCon         = l_IDRS.getInt(1);    // Get country ID
            String l_countryName = l_IDRS.getString(2); // Get Country name

            // Bind exchange rate to column.
            l_updateStmt.setFloat(1, Integer.parseInt(l_Rate));

            // Bind the home country Id to column. The home country is always USA.
            l_updateStmt.setInt(2, 1);

            // Bind the new country Id to column.
            l_updateStmt.setInt(3, l_newCon);

            int l_no = l_updateStmt.executeUpdate();


            // Add the details to the Vector
            l_row.addElement(Integer.toString(l_newCon));
            l_row.addElement(l_countryName);
            l_row.addElement(l_newId);
            l_row.addElement(l_Rate);
            l_table.addElement(l_row);

          } else // No country in the table for the corresponding currency.
             System.out.println("No country for the Currency " + l_newId);
        }
        HRSServletHTML.showUpdate(p_user, p_res, l_table);

    } catch (Exception ex) {  // Trap Errors
      System.out.println("Error in Updating :" + ex.toString());
    }

  }
  ...
}

The following code comes from xmla2a.hrs.HRSServlet.service. It shows how the HRS displays raw, unformatted XML in a browser.

...
   if(l_reqType.equals("SHOW_XML_FOR_X_RATES")){
      PrintWriter l_out = p_response.getWriter();
      p_response.setContentType("text/xml");

      int l_c = 0;
      File l_fileName = new File(this.m_xmlFileName);
      FileReader l_fread = new FileReader(l_fileName);
      while((l_c = l_fread.read()) != -1)
        l_out.write(l_c);
   }
...

< Back to Introduction


Questions or comments? Post a message in OTN's Sample Code discussion forum or send email to the author.

B2B with XML: Exchange Rate Provider
Author: Robert Hall, Oracle Corporation
Date: August 2000

This document is provided for information purposes only and the information herein is subject to change without notice. Please report any errors herein to Oracle Corporation. Oracle Corporation does not provide any warranties covering and specifically disclaims any liability in connection with this document.

Oracle is a registered trademark and Enabling the Information Age is a trademark or registered trademark of Oracle Corporation. All other company and product names mentioned are used for identification purposes only and may be trademarks of their respective owners.

Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
U.S.A.

Worldwide Inquiries:
+1.650.506.7200
Copyright © Oracle Corporation 2000
All Rights Reserved


E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy