• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
E-gineering

E-gineering

  • Who We Are
    • Our Story
    • Leadership Team
    • Whole Team
  • What We Do
    • Practices
    • Full Services
    • Success Stories
  • Working Here
    • Careers
    • Work Life
    • Community Life
    • Fun Life
  • Blog
  • Contact Us

Converting Database Data Directly to XML

January 26, 2009 by Christian Desserich

XML-01I had another interesting problem when an application framework we’ve been working with came out with a new version. Before, a value relating to the application user’s “Position Name” (i.e. Manager) was a user-entered value. In the new release, this value was supposed to come from an XML configuration. Our client had already entered over 200 different positions and understandably didn’t want to take the time to hand enter each one into this new configuration. I found out that DB2 has the XMLSERIALIZE() function and decided that this would be the easiest way to accomplish this without hand-typing each position name back into the system.

As mentioned above, in the original version of the framework the position name was typed in, but in the new version the configuration would be populated in a drop-down. Plus the configuration XML added two new elements that were obviously not present before. So the technique I used capitalized on some of the knowledge I gained working out the Vacuum of Columns. It turned out to be a simple select with two “dummied” columns.

select distinct XMLSERIALIZE(content XMLELEMENT(name "Position_Name", XMLELEMENT(name "Value", system_users.position_name), XMLELEMENT(name "Dollar_Limit", CAST(NULL AS VARCHAR(1))), XMLELEMENT(name "Level", CAST(NULL AS VARCHAR(1)))) as VARCHAR(120)) as "Result" from system_users

You can see that I used the cast(null as ___) technique from my earlier post to make sure the element tags existed even though they were empty, so that I didn’t have to put those in by hand either. I executed this in SQireL and just cut and pasted it into the configuration and voila! All done with little fuss and less muss.

This particular example was on the verge of not being worth the time it took to figure this out, but I again learned something that may be extremely handy in the future, and it might save someone else some time, too. For more information, here is the article on IBM developerWorks :

http://www.ibm.com/developerworks/data/library/techarticle/dm-0511melnyk/

Category: Data

About Christian Desserich

Previous Post:The Vacuum of Columns
Next Post:JavaMail and Gmail Simplified Part 1: Introduction

Let’s work together

Get in touch with us and send some basic info about your project.

Get in touch!

Social

Follow along on social media

  • Mail
  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter

Navigation

Home

Who We Are

What We Do

Working Here

Blog

Contact Us

Contact

8415 Allison Pointe Blvd
Suite 200
Indianapolis, IN 46250

317.348.1780

info@e-gineering.com

© Copyright 2023 | E-gineering, Inc.

Return to top