Creating an XML Schema Definition (XSD) document with the DB2 tools for Visual Studio 2005 - Page 2
October 24, 2006
5. Create another XSD file that will use the complex CanadianAddress data type by performing the following steps:
a. Create a new XSD file by pressing New>File as you did in Step 1.
b. The XML Schema editor opens. Right-click in the middle of the designer, only this time select Add>New element (instead of New complexType as you did in Step 2):
c. In the same manner in which you added the Address element for the CanadianAddress XSD in Step 3, add a Name element to the first field and associate it with a string data type.
d. In the second row, add an Address element and manually type in the data type name CanadianAddress beside it.
When you have completed both Steps 5c and 5d, the XSD editor should look this:
6. Associate the CustomerAddress XSD (which defines the CanadianAddress complex data type) with this new XSD as follows:
a. Click the gray area (in the previous figure) of the Customer XSD editor.
b. Ensure that the Properties window displays <xs:schema> using the drop-down control:
If you cant see the Properties window, press F4 after Step 6a.
c. Click the ellipsis (...) beside the include field in the Properties window.
The Xmlinclude collection window opens.
d. Click the Add button.
e. Enter CanadianAddress.xsd for both the id and schemaLocation fields in the <xs:include> Properties window, and click Close:
f. Save this XML Schema Definition document as Customer.xsd in the same location (and by using the same method) that you used to save the CanadianAddress XSD in Step 4.
g. After youve saved the Customer XSD file, click View>Refresh to refresh the view of the designer palette.
When you associate the CanadianAddress XSD with the Customer XSD, Visual Studio 2005 automatically associates the two, as shown below:
This is a very useful and informative feature because it lets you quickly see what data types are included in the complex CanadianAddress data type.
If you find your IDE getting too busy, you can collapse this association by clicking the toggle ():
You verify that the Customer XSD includes the CanadianAddress XSD, which defines the CanadianAddress complex data type, by looking for the INCLUDE function in the code (its on the third line):
Wrapping it Up...
In this article, I showed you how to use Visual Studio 2005 to create a somewhat complex XML Schema Definition document that leverages a collection of XSDs: one that will be used for the purpose of validating or decomposing an XML document, while the other defines a complex data type that is used in the XML document
In my next article, Ill show you how to register this XSD with the XSR thats built into the DB2 9 data server. Ill also discuss some of the unique capabilities DB2 9 offers XML developers for XML Schema management.
About the Author
Paul C. Zikopoulos, BA, MBA, is an award-winning writer and speaker with the IBM Database Competitive Technology team. He has more than ten years of experience with DB2 and has written over sixty magazine articles and several books about it. Paul has co-authored the books: DB2 9 New Features, DB2 Version 8: The Official Guide, DB2: The Complete Reference, DB2 Fundamentals Certification for Dummies, DB2 for Dummies, and A DBA's Guide to Databases on Linux. Paul is a DB2 Certified Advanced Technical Expert (DRDA and Cluster/EEE) and a DB2 Certified Solutions Expert (Business Intelligence and Database Administration). In his spare time, he enjoys all sorts of sporting activities, running with his dog Chachi, and trying to figure out the world according to Chloë his new daughter. You can reach him at: firstname.lastname@example.org.
IBM, DB2, DB2 Universal Database and PureXML are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both.
Microsoft and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other countries.
Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.
Other company, product, and service names may be trademarks or service marks of others.
© Copyright International Business Machines Corporation, 2006. All rights reserved.
The opinions, solutions, and advice in this article are from the authors experiences and are not intended to represent official communication from IBM or an endorsement of any products listed within. Neither the author nor IBM is liable for any of the contents in this article. The accuracy of the information in this article is based on the authors knowledge at the time of writing.