Gone are the days of storing XML data as a CLOB or shredding to relational tables. The pureXML feature of DB2 9 has revolutionized support for XML data—handling XML as a new data type that is stored in a natural hierarchy—different from relational data. pureXML's seamless integration of XML with relational data speeds application development, improves search performance with highly optimized XML indexes, and is flexible because you can use both SQL and XQuery to query XML data. XML data, stored in pureXML, can be exposed as Web Services through the Data Web Service mechanism. (See Part 1 of this series.)
How pureXML support works in XFG
The first thing we do is to create a mini-pureXML application based on a table defined in DB2 to illustrate the detailed steps of pureXML support in XFG. Table 1 shows the structure of the table. Before the illustration, we insert a sample record as pureXML reference instances in which the XML1 column doesnât bind to any schema and XML2 column binds to a registered schema—Express schema as seen in Listing 1. Note: A pureXML reference instance is an XML template used to generate the XHTML/XForm with XFG, as we know XFG can generate the form from either XML or WSDL.
Table 1. Overview of the table structure

Listing 1. Express schema

After the table is created in the DB2 database, you use Data Studio to create a SQL file containing the SQL statement:
INSERT INTO XFGDEMO (ID, NAME, XML1, XML2) VALUES (:id, :name, :purexml1, :purexml2)
Then you create the Data Web Services. Please refer to Resources for a description of creating Data Web Services from the
SQL file. When you create the Web service sample, generate a WSDL file named
insertRecord.wsdl which will look like the file in Listing 2. You can see two pureXML parameters in the generated WSDL file, PUREXML1 and PUREXML1. These two pureXML fields bind to xsd:anyType, and in the following steps youâll use XFG to visualize them into XHTML/XForm fragments.
Listing 2. pureXML parameters in the WSDL file

After you create and deploy the Data Web Services from Data Studio, you can use XFG to generate the XHTML/XForms and the corresponding XML files to communicate with the services.
Select the insertRecord.wsdl file, right-click on the WSDL file, and choose the Generate XHTML/XForms wizard from the XForms Generator menu. Figure 1 shows the first wizard step:
Figure 1. First step in the XFG wizard

Generate validation information
In XFG you can append additional validation constraints to pureXML fields. When you select the Generate validation information option, you then see a validation editor wizard page to configure additional validation rules in the following steps.
Retrieve the pureXML instance from the database
XFG supports two ways to visualize pureXML fields in WSDL. One is to use a pureXML instance in the local file system, and read the binding schema from local file system. The other is to use the pureXML instance in the database and retrieve the registered schema from the XML Schema Repository (XSR). If you select Retrieve PureXML instance from Database checkbox, you can use both options; if you don't select it, you can only use a schema in the file system. Check this box. Click Next.
On the next screen, choose the insertRecord operation and click Next. You then see the Configure PureXML wizard page as in Figure 2. Here, XFG recognizes all of the pureXML parameters. You need to specify the pureXML instances as references in order to generate a visualized XHTML/XForm and then retrieve the pureXML instances from the database. Please note that, of the reference pureXML instances, PUREXML1 doesnât bind to any schema and PUREXML2 binds to the registered schema as in Listing 1.
Figure 2. Configure PureXML wizard page

Click Next and the Validation Editor screen shows. Here, you add some validation rules on PUREXML1, which doesnât bind to any schema.
Figure 3. Validation editor

Continue through the wizard and finally click Finish to generate the XHTML/XForms. The generated XHTML file is insertRecord.xhtml. Figure 4 shows the generated form. (See a larger version of Figure 4):
Figure 4. Generated XHTML/XForm rendered in Firefox

In the fragments of the generated XHTML form in Listing 3, you
see two fieldset tags. Each tag is generated from the
specified instance in the database and corresponds to a pureXML parameter in the
WSDL file from Listing 2.
Listing 3. pureXML XForm fragments

XFG generates bind information, in Listing 4, for the registered schema (you saw the schema in Listing 1).
Listing 4. pureXML bind information generated from the registered schema

Meanwhile, XFG also generates the bind information in Listing 5 for the PUREXML1 validation rules which you set in the wizard.
Listing 5. pureXML bind information generated from the validation rules

Multiple model merging for submission
In the generated XHTML/XForm, you'll find three XForm Models:
- The first model is the global one that corresponds to the WSDL operation
insertRecord. This model contains only four elements:ID,NAME,PUREXML1,PUREXML2. The elements map to the four parameter names in Data Web Services. - The second and third models are the pureXML models for parameters of PUREXML1 and PUREXML2, retrieved from the database or the local file system. All the data changes of the two pureXML fieldsets in XHTML/XForm applies to these two models.
Before submitting to Data Web Services, XFG will merge these two pureXML models into the first global XForm model using the generated client script in XHTML, as in Listing 6. This script is executed at the client as part of the XHTML form when the form is submitted.
Listing 6. Model merge XHTML script

The merged data model, in Listing 7, is a complete SOAP message, which the client submits directly to the Web service to insert a new record into the table using the data from the form.
List 7. Merged model

In this article, we briefly described the DB2 pureXML support in XFG. With the pureXML support in XML Forms Generator (XFG), you can visualize pureXML into an XHTML-based XForm for users. In addition, you can rely on XFG to retrieve the registered related XML Schemas of pureXML instances and generate type information. And the validation constraints can be fetched and added into the target pureXML XHTML/XForms. Obviously the pureXML support in XFG makes it easy to build forms interfaces for XML instances stored in pureXML. In this article series, we introduced XForms, XFG, Data Studio, Web services, and the pureXML feature support. Through these two articles, you can easily start to use XFG to generate functional XHTML/XForms UI for the backend Data Services to build a complete data service solution.
| Description | Name | Size | Download method |
|---|---|---|---|
| Code sample for Listing 1 in article | Listing1.zip | 1KB | HTTP |
Information about download methods
Learn
- Data Web Services: Build Web services the new way to access IBM database servers: Service-enabling your access to DB2 and Informix Dynamic Server(Vijay Bommireddipalli, developerWorks, December 2007): In this overview of Data Web Services, learn to build a Data Web Service and generate Web services-based access to your database.
- The DB2 XML wiki: Find papers, presentations, and demonstrations related to DB2 9 and pureXML. The authors recommend the DB2 Demo program (George Baklarz, developerWorks, updated February 2008) as a starting point.
- XML Forms Generator/Data Studio Overview (alphaWorks, November 2008): Generate forms that conform to the XForms 1.0 standard with this Eclipse plug-in.
- Using DB2 XML and Java (Anson Kokkat, developerWorks, October 2006): Check out a tutorial on developing in the Java environment with DB2 XML.
- XML Forms Generator/Data Studio Overview (alphaWorks, November 2008): Generate forms that conform to the XForms 1.0 standard with this Eclipse plug-in.
- XForms tutorial (W3 Schools): Learn to use XForms, the next generation of HTML forms, in your applications.
- DB2 pureXML wiki: Keep up with the latest on DB2 pureXML enablement.
- XForms area on developerWorks: Browse for more information related to XForms.
- Web services on developerWorks: Get the resources you need to advance your skills in the SOA and Web services area.
- Information Management on developerWorks Visit and find resources for learning how you can use SOA and Web services with IBM Information Management products.
- IBM XML certification: Find out how you can become an IBM-Certified Developer in XML and related technologies.
- XML technical library: See the developerWorks XML Zone for a wide range of technical articles and tips, tutorials, standards, and IBM Redbooks.
- developerWorks technical events and webcasts: Stay current with technology in these sessions.
- The technology bookstore: Browse for books on these and other technical topics.
- developerWorks
podcasts: Listen to interesting interviews and discussions for software developers.
Get products and technologies
- DB2 Express-C: Download a free trial version of the DB2 Express 9 database server.
- DB2 for Linux™, UNIX™, and Windows.: Download a free trial version of an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML.
- XML Forms Generator/Data Studio on
alphaWorks: Download the standards-based, data-driven Eclipse plug-in that generates functional forms with XForms mark-up embedded within an XHTML document from a XML data instance or a WSDL document.
- IBM Data Studio: Download a free trial version of an integrated database development environment that speeds application design, development, and deployment as it increases data access efficiency and performance.
- IBM trial software for product evaluation: Build your next project with trial software available for download directly from developerWorks, including application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
Discuss
- Participate in the discussion forum.
- Data Studio Team
blog: Check out this blog and get involved in the Data Studio Space.
- XML zone discussion forums: Participate in any of several XML-related discussions.
- developerWorks blogs: Check out these blogs and get involved in the developerWorks community.

Xiao Feng Zhao is a staff software engineer in the China Emerging Technology Institute, China Software Development Laboratory. He concentrates on IBM Incubator projects. His interests include Web 2.0, SOA, J2EE, and Web technologies. He is currently working on PoCs development for Ajax and SOA standards.

Qiang Wang works as a technical leader in the China Emerging Technology Institute, China Software Development Laboratory. He concentrates on IBM Incubator projects and SOA-related topics. His interests include J2EE, SOA, MDA/MDD, AOP, RUP, and project management. He is currently leading some industry related SOA solutions.

Susan Malaika is a Senior Technical Staff Member in the IBM Information Management Group (part of IBM Software Group). Her specialties include XML, the Web, and databases. She has developed standards that support data for grid environments at the Global Grid Forum. In addition to working as an IBM product software developer, she has also worked as an Internet specialist, a data analyst, and an application designer and developer. She has also co-authored a book on the Web and published articles on transaction processing and XML. She is a member of the IBM Academy of Technology.

Keith Wells is a software engineer at IBM in Research Triangle Park, N.C. Mr. Wells has been involved with Emerging Technologies and the Emerging Technologies Toolkit for several years. Currently, he is exploring opportunities with compound documents, model-driven development, software standards, and XML-based technologies.
Comments (Undergoing maintenance)





