IDS 11 purifies XML
IDS 11 purifies XML
Find out what happens when "Cheetah" speaks XML.
By Jean Georges Perrin July/2007
Printer-Friendly Version
Email this Story
Bookmark to del.ico.us
Digg It!

Jean Georges PerrinAs an application developer, I love Informix Dynamic Server (IDS) 11 (which was code-named "Cheetah" before its release). Why get so excited? Because "Cheetah" brings tools that make my day-to-day life easier. I also love XML. For me, XML is the sign of a new generation of IT professionals. It's the clear separation between a generation focusing on don’t-waste-that-extra-byte and a generation focusing on making IT understandable by its peers.

And now, my favorite engine embraces my favorite language. In my article on DB2mag.com, I'll show you how my company, GreenIvory, uses XML and IDS 11 for Web publishing, and how these technologies can benefit your company, too. You'll learn what happens when Cheetah speaks XML and how it can work to your benefit.

What is XML anyway?

XML stands for eXtended Markup Language. It's often a text file; it can also be a stream, compressed, “binary’zed”, encrypted, and tortured in many other ways, but XML is (and remains) textual information (see. Figure 1)


Now you know about all that should be known about XML. Of course, you can still learn about XSL, XPath, namespaces, XML Schema, DTD, and plenty of other acronyms, but you’ll do that on your spare time.

XML Activation

Once you've installed Cheetah, there's nothing more to do. You simply need to tell IDS that you're going to use the XML virtual processor (VP). To do so, edit the ONCONFIG file, and add:

VPCLASS idsxmlvp

You can have several VPCLASS lines in your ONCONFIG file, if needed. Typically, you could find one for Krakatoa, the Java-in-the-engine extension.

Once you have restarted your engine, you can check that everything is fine:

onstat -g glo 

should return:

Three IDS Families

IDS comes with nine functions divided into three families.

Each function has its character large object (CLOB) counterpart: The “base” function will return LVARCHAR(32739) and the CLOB version of the function will return a CLOB (okay, that was easy). Example: genXML() returns a LVARCHAR(32739); genXMLCLOB() returns a CLOB.

To make examples more appealing and more attractive, I have manually indented them.

IDS Generations

The first family is XML publishing & generation. They help you get the data from IDS in an XML format. All those functions are prefixed by “gen”.

The functions in this family are:

  • genXML ( root_element , rows )
    genXMLCLOB ( root_element , rows )
  • genXMLElem ( row , element )
    genXMLElemCLOB ( row , element )
  • genXMLQueryHdr ( row , query )
    genXMLQueryHdrCLOB ( row , query )
  • genXMLQuery ( row , query )
    genXMLQueryCLOB ( row , query )
  • genXMLSchema ( row , element )
    genXMLSchemaCLOB ( row , element )

genXML

This function returns an XML representation of the result set. Note that there is no root element.

SELECT genXML(customer, "customer-row") FROM customer WHERE city="Menlo Park";

Notice that the white spaces are kept as the fields are mostly of type CHAR(xx).

genXMLElem

genXMLElem behaves in a very similar way to genXML. The main difference is that it cuts field into element, whereas genXML uses attributes. genXMLElem also creates a root element.

SELECT genXMLElem(customer, "my-customers") 
FROM customer WHERE customer_num="114" OR customer_num="112";

genXMLQuery

This function creates an XML document from a SQL query.

EXECUTE FUNCTION genXMLQuery(
'my-customers', 
'SELECT customer_num, lname FROM customer WHERE fname MATCHES "Frank"');

genXMLQueryHdr

Same idea as the previous function, but genXMLQueryHdr creates a more sophisticated XML document, taking the encoding from the database.

EXECUTE FUNCTION genXMLQueryHdr(
'my-customers', 
'SELECT customer_num, lname, trim(city) AS city FROM customer 
WHERE fname MATCHES "Fran*"');

Note the result of the trim() function: for its non-XML use, it removes the extra white spaces.

genXMLSchema

This function generates a complete XML Schema from the table structure.

SELECT genXMLSchema(customer, "my-customers") 
FROM customer 
WHERE phone MATCHES "408-7*";

Note: with Cheetah xc1 (IDS v11.10.xc1) there is a small issue in the header. Right now, it produces "xs:schema" and it should produce "<xs:schema". The IBM team told me this issue will be corrected in Fix Pack 2.

Extraction

The second family of functions is about XML query & extraction. Basically, you get information in XML based on an XML query. These functions are prefixed by “extract:”

  • extract ( xml_string , xpath_expression )
    extractXMLCLOB ( xml_string , xpath_expression )
  • extractValue ( xml_string , xpath_expression )
    extractXMLCLOBValue ( xml_string , xpath_expression )

The CLOB syntax changed a bit, but you've got the idea, right? extract() returns a LVARCHAR(32739) and extractXMLCLOB() returns a CLOB.

Both functions work on XML content, so you need to have some XML already in your database, which isn't really the case with our favorite stores_demo… So, you need to modify it a bit…

I hope you're not too tired from typing all that. You have surely noticed (while typing): what is being inserted in the table is the result of a genXMLElem() function.

SELECT extract(xmlcol, '/my-customers/row/fname') FROM xmlcustomer;

This example returns the last() last name.

SELECT extract(xmlcol, '/my-customers/row[last()]/lname') FROM xmlcustomer;

extractValue

With a similar syntax as extract(), extractValue() focuses on the value, ignoring the elements. To see the differences, I ran similar examples.

Here is the “first” first name. Note the new XPath syntax.

SELECT extractValue(xmlcol, '/my-customers/row[last()]/lname') FROM xmlcustomer;

As a bonus example, here is the last row:

SELECT extractValue(xmlcol, '/my-customers/row[last()]') FROM xmlcustomer;

XML Validation

Finally, the third family of functions is simply about XML validation. Functions include:

existsNode ( xml_document , xpath_expression , namespace ): Checks the existence of some nodes (this function is useful in the "where" part).

idsXMLParse ( xml_document ): Asks Cheetah to growl if the XML is well-formed (it only works if you have a sound card).

XML and IDS at Work

My company, GreenIvory, offers a software package that focuses on Web publishing. Its leading product, RedLion, is using those features to report statistical information for Web sites such as InformixMag.com.

Here's how. Once you execute a query returning XML, it comes in text. This might not be very useful if you want to exploit XML as XML (for example, to apply a style sheet on the result to publish it). At GreenIvory, we streamline the result of the query, transforming it into XML and making it available as a DOM object. To do so, we developed two libraries of open source (Apache2 license) “commons,” which can be downloaded from our Web site.

Thanks to XML and IDS, GreenIvory has been able to provide specific statistical information about our publication process and sites. Changing the reporting information is only a matter of changing the style sheet. (Well, almost. In any case, that’s our goal.)

IDS and XML: So Far, So Good

IDS has fulfilled GreenIvory's needs and allowed us to implement new features for our software package. We could have done it in a different manner, but the cost would have been higher, both in development time and in daily CPU cycles.

Of course, we hope to see more XML features like the ability to shred XML, to use XQuery on relational data, and so on. But we need to wait for the feature list of Cheetah2.

If you want to give it a try, grab a copy of Cheetah, install it (it even runs on Vista), download the examples and go.

Jean Georges Perrin is the CEO of GreenIvory, an ISV focusing on solutions to provide the right information at the right time. Jean Georges is XML certified by IBM and has been elected on the IIUG Board of Directors since 2002.


Comments? Questions?

Give us your feedback or ask a question of the author.

Please enter your e-mail address below:

CAREER CENTER
Ready to take that job and shove it?
SEARCH JOBS
RECENT JOB POSTINGS
CAREER NEWS
10 Search Engines You Don't Know About
Go beyond Google and get vertical. These specialized search sites will help you find the business information you need -- fast.

Subscribe to the new digital version of IBM Database Magazine
New Digital Version

Sponsored links:



Subscribe to the IBM Database Magazine Newsletter

Email Address *
First Name
Last Name
HTML Preference
HTML Text
 

Fields with * are required.

 




Visit these other IBM and TechWeb Partner Sites: :
Maximizing ROI Through Business Process Management (BPM) and Service-Oriented Architecture (SOA)
Internet Evolution – The Macrosite for News, Analysis, & Opinion About the Future of the Internet
Business Innovation – Technology Strategies and Solutions for Driving Business Success