Level: Introductory Ajay Aggrwal (aaggrwal@us.ibm.com), Advisory Software Engineer, IBM
29 Nov 2007 IBM® Database tools for Microsoft® Visual Studio 2005
introduces a new set of Web service-oriented features that expose the latest DB2®
pureXML™ functionality. The new release provides the means for a dramatic increase in
developer productivity. The new IBM Database Add-ins for Visual Studio 2005 offer a
number of features that make working with pureXML much easier. These features range
from the creation of Web services from annotated XML schemas, to XSR
comparisons, to XSR XSLT support. This article provides a detailed
overview and usage guide of IBM XML tools for DB2 Version 9.5.
Prerequisites
This article assumes that you are accessing DB2 for Linux®, UNIX®, and
Windows® V9.5.
You will also need the IBM Database Add-Ins for Visual Studio 2005 V9.5. The Add-Ins tooling is available in one of the following ways:
To become more familiar with the general features of the IBM Database Add-ins for
Visual Studio, read the "Overview of IBM Database Add-ins for Visual Studio 2005"
article and the "Develop proof-of-concepts .NET applications" tutorial series (see Resources).
XML support
The DB2 V9.1 release introduced new features for managing, storing, and querying XML
data. Some of the new features include:
- The XML data type, which enables DB2 to store XML documents in their native hierarchical format
- Support for the XML query language based on industry standards, including new XML extensions to SQL (also called SQL/XML)
- Support for validating XML data based on user-supplied schemas, which allows application developers and database administrators to enforce data integrity constraints for XML data stored in DB2
The XML capabilities were enhanced as part of the IBM Database Add-ins V9.5 release.
Support for Web services for annotated XML Schema, XML Schema Repository (XSR) Compare, and XSLT
Support were added as part of the V9.5 release. These enhancements will increase
usability of the XML feature set, thus helping developers be more productive.
Web services support for annotated XML schema creation
The new release has added the capability to use a Web services as a source for an
XML schema. The XML schema can be inferred from the WSDL result of the Web service.
The new release now has an additional option to define the Web service as an input
for the XML schema source, as Figure 2 shows. In the previous
release, the only available inputs were to use registered XML schema or a document
from a file. In order to use a Web service as a source for the XML schema, follow
these steps:
In the Server Explorer, right click on XML Schema Repository
and select Add Annotated XML Schema, as shown in Figure 1:
Figure 1. Add annotated XML schema
This brings up the dialog with the three options shown in Figure 2. Select Use document from a web service to create a new annotated XML Schema.
Figure 2. Select XML schema source
Enter the Web service, and click the Validate wsdl button to validate the Web
service. Once the WSDL is validated, you can select a root node to create the
annotated XML Schema, as Figure 3 illustrates:
Figure 3. Select root element
Add a target table by right-clicking the dialog box. Select Add Target Table, which brings up a dialog with a list of tables.
Figure 4. Add target table
Select a table and then map the columns from Source XML Schema to the target table
in the Mapping Editor. Figure 5 shows the columns being mapped:
Figure 5. Mapping columns
Once mapping is complete, using the Test option, verify the design to make
sure the source schema and target table mapping has been done correctly. Figure 6
shows this step:
Figure 6. Testing the design
You can view the generated source code using the option View Source. Select
either a Text Editor or the XML Designer for viewing the code, as shown below:
Figure 7. View source
Figure 8 illustrates the generated code:
Figure 8. Generated code
You can define the source XML file, or use the editor to define XML on the Test
Form. You can define the Web service to verify the created annotated XML Schema.
The Test Form dialog shows the result of the test operation. Figure 9 illustrates this:
Figure 9. Test form
Once the design is validated, select Save in the Visual Studio to save it to
the database.
Clicking Save brings up the Register annotated XML schema dialog,
where you can define the XSR name, owner, comments, schema location and decomposition
options. Figure 10 shows this dialog:
Figure 10. Register annotated XML schema
After successful completion of the save operation, the registered XML schema is
shown under the XML Schema Repository node in the Server Explorer.
Various options are available for the newly created annotated XML schema. Figure 11
shows the many different options:
Figure 11. Annotated XML schema
definition from Server Explorer
If you select "Open definition" as shown above, you will see a screen like that in
Figure 12. Figure 12 displays the definition of a selected annotated schema. It displays the
XML schema file name, XSR name, owner, decomposition
and any dependencies:
Figure 12. View definition of an
annotated XML schema
XML schema repository compare
Tracking any changes or updates to an XML Schema can be problematic and very time
consuming. To overcome this situation, an option to compare XML Schemas has been
added to the V9.5 release. Users can select a XML schema and, in the pop-up menu, select
Compare XML Schemas. This option compares schemas and notifies users of any differences that are found between the two schemas as part of this operation.
Figure 13. XML Schema Repository compare option
Schemas to be compared can be selected in the XSR Object Compare dialog, as Figure 14
shows. A user can define the original XSR object and choose
its dependencies as well as the XSR to be compared with and its dependency. Once XSR
objects have been selected for comparison, select Compare.
Figure 14. Choose XSR objects for compare
If each XSR object contains dependencies, then the dependencies
section gets populated. Users can only select one document at a time. For example, a
user can select either master document or one of the dependent documents to be
compared. The XSR Object Compare drop down list contains all the registered schemas.
A user can choose the required schema using this drop down.
In the XML Schema Repository Object Compare dialog, the Diff option allows users to
modify the compare options. For example if a user selects the option "Ignore
comments," then comments are not compared in both XML schema documents.
Figure 15. XSR Object Compare options
The difference between two schemas is saved in a file and displayed with color
coding. The differences are labeled as: added, removed, changed, moved from/to and
ignored.
Figure 16. XSR compare output
If the two XSRs being compared are exactly the same, the message "Files
identical for the given options" is displayed.
Generate a Web service for an annotated XML schema
DB2 V9.1 enabled users to create and register annotated XML schemas for XML document
shredding and the validation of input documents against these schemas prior to
insertion. The enhancements as part of IBM Database Add-ins for Visual Studio 2005
V9.5 provide an easy way to create and register annotated XML schema using a simple
mapping designer. Using the mapping designer also creates a Web service for the
annotated XML schema. Once annotated XML schema is registered in the DB2 XSR, it can be used for shredding and validating XML documents.
To generate a Web service for an annotated XML
service, you need to select Generate Web Method form the Server Explorer. An
ASP.Net Web service project should be open to add the code. The generated code is
the same kind of code that is used (MS XSD validation APIs) in the XML designer to
validate XML documents. When Client XML schema validation code is generated, a class
is generated which allows users to pass their document for validation. Figure 17
shows this step:
Figure 17. Generate Web Method
The generated code is displayed in the editor, as Figure 18 illustrates:
Figure 18. Generated web methods
After the code is generated, it can be tested by selecting F5 (Start debugging
option), which brings up a browser window with the Service Description and Shred method.
Figure 19 shows this browser:
Figure 19. Testing generated code
XSLT support enhancement
The Generate XML Helper Code option creates a project in the Solution Explorer with
sample code. This new feature provides sample code to the users, which can be used
as a starting point for coding. This option can be invoked from the XML Schema
Repository node in Server Explorer. Simply, select the XML Schema Repository
and choose Generate XML Helper Code as Figure 20 shows:
Figure 20. Generate sample code option
Figure 21 shows a sample code that might be produced from invoking this option:
Figure 21. Generated sample code
The generated code is added as a part of a new project db2XmlHelperSample. The
generated code file XMLUtil.cs has sample code for XSL Transformation and validation.
It provides a starting point for coding to the users who can build on top of this or
use it create their own applications. When executed, this sample code displays a
dialog, which shows a sample transformation and XML validation.
Figure 22. Generated sample dialog
Clicking on the Validate Sample button brings up the validate dialog and a
sample XML snippet. Clicking on theTransform Sample button brings up a
formatted sample report. Hopefully this example shows you the ease with which code can be created and used in an application.
-
Summary
The new set of enhancements to the XML functionality as part of IBM Database Add-ins
V9.5 release exposes DB2s latest pure XML functionality and help developers to create
applications faster and easier with DB2. These powerful features will enhance user
experience while utilizing XML functionality in DB2. The new Web service-oriented features provide basic building blocks to creating applications while utilizing DB2s rich XML functionality.
Resources Learn
Get products and technologies
- Download
IBM product evaluation versions
and get your hands on application development tools and middleware products from
DB2®, Lotus®, Rational®, Tivoli®, and
WebSphere®.
Discuss
About the author  | 
|  | Ajay Aggrwal is Advisory Software Engineer with the IBM Database Add-ins for Visual Studio 2005 team. |
Rate this page
|