XML to SQL Java classes for dynamic selection
WDSC also provides two Java classes to do the same thing dynamically: SQLToXML and XMLToSQL. They are stored in two jar files:sqltoxml.jar and xmltosql.jar. Although you do some basic Java coding here to use these classes, it doesn't require learning the details of XML SAX or DOM parsers.
If we have the wizards that are easy to use, why bother with Java coding examples to do the same thing? The Java classes allow you to specify the selection criteria for the queries at runtime. You may want to embed these functions as built-in services in your own application. In that case, you may want to use these IBM classes. They are nice to use because they don't require you to buy any extra prorietary software (see the DB2 XML Extenders below).
Buy DB2 XML Extenders to map XML to SQL
WDSC also has an RDB-to-XML mapping editor that can create a definition (Data Access Definition) to insert XML documents into an SQL table in a DB2 database. This tool is a lot more powerful than the basic SQL-to-XML wizard but requires you to buy IBM's DB2 XML Extender -– an expensive add-on to DB2 on the iSeries -– to run the DAD and load XML to DB2. If you won't be programming in Java, need complex XML to SQL mapping support and plan on doing lots of XML applications, this high expense might be justified.
Using Java to parse XML documents vs. RPG
RPG allows you to call API programs. IBM supplies an XML parser on the iSeries that COULD be used to write your own custom parser logic. Do other consultants and IBMers teach you how to do this? Sure. Do I think this is a good idea? Absolutely not! While RPG is a great language for writing business logic on an iSeries server, there are MANY scenarios YOU would recognize RPG is a bad solution to a problem. (Writing a navigational system for a rocket that continuously calculates its course is another example.)
WDSC and Java offer MANY options and levels of parsing support for XML by comparison:
- WDSC's XML to SQL wizard -- No coding at all
- IBM's SQLToXML class or Apache's Commons Digester class to search and parse complex documents -- about five or six lines of Java typically
- JAXB support (Java for XML binding) in the latest web services standards pack from Sun -- about five to 10 lines of Java to create Java objects from XML
- Using the JDOM framework to create Java DOM objects (from www.jdom.org)
- Complete custom parsing logic using Xerces SAX and DOM parsers in Java (still a lot less work than RPG)
Return to main tip, Generating XML from SQL data.
Dig Deeper on Web Tools
iSeries shops are placing Web development and Web enablement at the top of their priority lists. But if you're just starting out, where do you begin? There are so many options that choosing the one right may seem like an impossible task.
Jim Mason, president of ebt-now, talked with assistant editor Deb Tart recently at the Northeast IBM User Conference in Framingham, Mass., about tools and techniques for developing for the Web and what his Web tool preferences are.