WDSC lets you tap into the power of XML

When it comes to Web development, XML is a powerful tool. But you don't need to be a skilled Java XML developer to make use of it. With WDSC you can easily create XML apps.

When it comes to Web development, XML is a powerful tool. But you don't need to be a highly skilled Java XML developer to make use of it. WebSphere Development Studio Client (WDSC) for iSeries Version 5 (both the Standard and Advanced editions) offers several options to create Web database and XML applications, including a number of helpful wizards.

Although WDSC doesn't build complete, custom XML applications for you, the XML tools go along way to saving time on developing XML applications. It DOES save time by generating a few simple XML applications and many components that you can use and customize relatively easily in your finished application.


Jim Mason

What XML does for Web applications

XML lets you store custom, hierarchical self-describing data in a document using a markup (or tag) language. This is VERY powerful for building applications. Similar to the way an RPG program using an externally described file with DDS can "see" the fields contained in a record format, an XML document has defined elements and attributes that are exposed to your application using an XML parser. With XML, the data structure can be complex data graphs using hierarchical relationships. In addition, XML documents can have associated Document Type Definitions (DTDs) or XML Schemas that further define the related document. Those external definitions can be used to build and validate XML document content.

In the example below, you can see how the markup tags "define" the elements in the XML document.

XML document example generated by WDSC SQL to XML wizard:

<?xml version="1.0" encoding="UTF-8"?>
<SQLResult xmlns="http://www.ibm.com/EMPLOYEE"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/EMPLOYEE
 empByLastName7.xsd">
    <EMPLOYEE>
        <LASTNAME>ADAMSON</LASTNAME>
        <FIRSTNME>BRUCE</FIRSTNME>
        <WORKDEPT>D11</WORKDEPT>
        <PHONENO>4510</PHONENO>
        <EMPNO>000150</EMPNO>
    </EMPLOYEE>
    <EMPLOYEE>
        <LASTNAME>BROWN</LASTNAME>
        <FIRSTNME>DAVID</FIRSTNME>
        <WORKDEPT>D11</WORKDEPT>
        <PHONENO>4501</PHONENO>
        <EMPNO>000200</EMPNO>
    </EMPLOYEE>

The schema below shows a "DDS-like" definition of the XML document above. Schemas provide a more precise definition of an XML document for a parser or application.

XML schema example generated by WDSC SQL to XML wizard:

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.ibm.com/EMPLOYEE"
    xmlns="http://www.w3.org/2001/XMLSchema" xmlns:EMPLOYEE="http://www.ibm.com/EMPLOYEE">
    <element name="SQLResult">
        <complexType>
            <sequence>
                <element maxOccurs="unbounded" minOccurs="0" ref="EMPLOYEE:EMPLOYEE"/>
            </sequence>
        </complexType>
    </element>
    <element name="EMPLOYEE">
        <complexType>
            <sequence>
                <element ref="EMPLOYEE:LASTNAME"/>
                <element ref="EMPLOYEE:FIRSTNME"/>
                <element ref="EMPLOYEE:WORKDEPT"/>
                <element ref="EMPLOYEE:PHONENO"/>
                <element ref="EMPLOYEE:EMPNO"/>
            </sequence>
        </complexType>
    </element>
    <element name="LASTNAME">
        <simpleType>
            <restriction base="string">
                <maxLength value="15"/>
            </restriction>
        </simpleType>
    </element>
    <element name="FIRSTNME">
        <simpleType>
            <restriction base="string">
                <maxLength value="12"/>
            </restriction>
        </simpleType>
    </element>
    <element name="WORKDEPT" nillable="true">
        <simpleType>
            <restriction base="string">
                <maxLength value="3"/>
            </restriction>
        </simpleType>
    </element>
    <element name="PHONENO" nillable="true">
        <simpleType>
            <restriction base="string">
                <maxLength value="4"/>
            </restriction>
        </simpleType>
    </element>
    <element name="EMPNO">
        <simpleType>
            <restriction base="string">
                <maxLength value="6"/>
            </restriction>
        </simpleType>
    </element>
</schema>

XML increasingly becomes more important for application development scenarios, especially Web-based applications. We use XML and related technologies to define and move data from almost any source generator to any target consumer. XML lends itself to easy transformations between a source and target.

The document object model

All of these frameworks provide support for creating, editing, validating and reading XML documents. Generally XML processing is done using streams over a document object model (DOM). The hierarchical document is represented as a set of nodes of different types: simple, complex and collections. The node set can be traversed by an application or parser, usually in sequential order.

An example of mapping the employee document to an Employee bean:

package empByLastName7;

import java.util.*;
import java.text.DateFormat;
import com.ibm.etools.xmlschema.beans.*;

/**
* This class represents the complex type <EMPLOYEE>
*/
public class EMPLOYEE extends ComplexType
{
  public EMPLOYEE()
  {
  }
  
  public void setLASTNAME(LASTNAME LASTNAME)
  {
    setElementValue("LASTNAME", LASTNAME);
  }
  
  public LASTNAME getLASTNAME()
  {
    return (LASTNAME) getElementValue("LASTNAME", "LASTNAME");
  }
  
In many applications, it's convenient to map the document to a corresponding set of Java beans for processing. Modeling documents as beans, complex types are mapped to Java classes, attributes and end-nodes (leaf nodes) are usually mapped to bean properties, and collections are mapped to array objects or vectors.

XML tools in WDSC

In addition to the Xerces XML parser and Xalan XSL processor, WDSC offers a reasonably good set of wizards to generate XML artifacts and simple applications. The editors are reasonable for editing the many XML artifacts you have to deal with in building applications: XML documents, XML schemas (.xsd), XML Document Type Definitions (.dtd), XML template files for use with XML database queries (.xst), XSL Extended Stylesheet Language for transforming XML to another format (.xsl), and XPath expressions for selecting nodes within an XML document.

You can even generate code to map XML to DB2 database tables using a wizard that creates a Document Access Definition (DAD). To run this application, you need to buy DB2 XML Extender on the DB2 platform you will run on. The DAD support for DB2 Extender allows complex XML to relational mappings.

IBM was nice enough to provide an affordable option that works with ANY relational database WITHOUT special extender software, a single class: SQLToXML. It is in a jar file (xmltosql.jar) in the WDSC directory tree. You'll need Java skills to use the class. Also, add the Xalan processor and Xerces parser to your classpath because it relies on those XML tools.

Using WDSC XML tools to build a Web application

Let's look at a common application scenario and then review some of the tools WDSC provides to help create our application. One type of application I've built several times involves querying a relational database to generate an XML document and then providing Web access to search and view the document contents. It's useful for applications that generate Web views on relatively static content such as an item catalog. Whenever the catalog changes, the XML catalog document can be regenerated and published to the Web application. The application I built was a Web Employee Phonebook reading an XML document generated from a database.

To build a simple Web XML application that can search, select and view data in an XML document generated from an iSeries DB2 table you'll use WDSC wizards to do the following:

  1. Import an iSeries database model from table definitions
  2. Create an SQL Select statement that allows searching a table
  3. Generate an SQL to XML database query generating an XML document and schema
  4. Create Java beans that model the XML document using the XML schema
  5. Create a client Java Web XML application to search and view the generated Java beans
  6. Test the generated application using the WebSphere runtime test environment built into WDSC

Doing all of that with basic XML tools (parsers, processors etc) is a complex task for a highly skilled Java XML developer. It's much easier to learn how to use the wizards and editors to create the basic components of an application, customize them and link them together in a Java XML Web application. You will need beginner-level Java skills as well as WDSC knowledge to build your application.

An earlier tip on generating a Java Web database application reviewed steps 1, 2 and 6 above in detail. The steps of interest in our XML application are 3, 4 and 5.

For steps 1 and 2, you'll use the database model import fairly often to capture iSeries data definitions in WDSC to build applications. If you are new to SQL, you'll probably want to use the SQL statement builder to build your SQL statements accurately.

Step 3: Generate an SQL to XML database query generating an XML document and schema
The XML tools offer a wizard to generate the XML database query easily: SQL to XML query. Just following the prompts; it's simple to reuse the SQL Select statement you created above to generate an XML document with your data and a corresponding XML schema.

Later, you can use the SQLToXML class to do the same thing dynamically in your Java application code if you need to. IBM provides this class and XMLToSQL to allow your applications dynamic read and write of XML documents to and from any relational database. This is a big plus as you develop more sophisticated applications with dynamic access. The classes are stored in a jar file:

x:ws_installdirwstoolseclipsepluginscom.ibm.etools.sqltoxml_5.01.

Step 4: Create Java beans that model the XML document using the XML schema
The next step is to generate Java beans that reflect the XML document elements. WDSC provides another wizard to generate the Java beans: Generate Java beans for creating XML instances of an XML schema. The XML schema was created in step 3.

This wizard generates Java beans that use the com.ibm.etools.xmlschema.beans package in the wsdbeans.jar file.

While the generated beans do NOT actually contain your data, they are place holders that can store the XML document data in a bean, as well as routines to load the XML data to the beans and update the XML document from the beans. A useful set of capabilities for a full XML application.

Step 5: Create a client Java Web XML application to search and view the generated Java beans
Here we use WDSC to generate a Java Web XML application based on MVC architecture with a Java servlet and a JSP that uses XSL to generate the output pages in your Web application. The input to this step comes from step 4 -- the Java beans you created. In my case, the Web application allows you to view and maintain employee entries in a phonebook, so I used the EMPLOYEE bean I generated in step 4.

While running the generated application "as is" only gives me the ability to enter a new EMPLOYEE phonebook entry, I can modify the generated application to add access to read the existing XML data and create a selection page in front of the detail view page. To create a select servlet, I'd use the sample Java beans in step 4 that read and write XML document data to the EMPLOYEE Java beans I created.

This process describes using the WDSC XML tools to generate basic components for a Java XML application. You do have to know Java to link all this is into a useful, running application, but you can at least test the individual components in WDSC.

As your Java skills grow, you can modify the generated Web application to do the following:

  • Dynamically query the database at runtime to generate XML
  • Store the generated XML document in memory as a byte array instead of a file
  • Generalize the web application and queries to query any table using JDBC metadata

---------------------------------------

About the author: ebt-now www.quickwebsupport.com

==================================
MORE INFORMATION
==================================

  • XML an increasingly valuable skill, experts say
    Understanding Extensible Markup Language (XML) is becoming an increasingly valuable asset for all IT professionals, especially systems and network managers.
  • Web-enabling legacy system using XML
    A Search400.com member was having difficulty using XML to Web-enable a legacy system. He needed to call RPG programs running on V4R5 from WebSphere running on an iSeries. Fortunately Jim Mason had some advice.
  • Web services: Many uses, many worries
    Fears about Web services security shouldn't dissuade organizations from implementing the technology, experts say. But security should be a consideration right from the beginning of any Web services project.


Jim Mason, president of , is an iSeries WebSphere engineer. ebt-now provides iSeries WebSphere, WebFacing project management, engineering, development and training services. For more tutorials, visit .
This was first published in June 2003

Dig deeper on Web Tools

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close