If you are having trouble viewing this email, click here.

December 2007 Newsletter

That's Cool! RPG-XML Suite Tips & Tricks for Developers
by Aaron Bartell

The RPG-XML Suite developers at Krengeltech have been at it again! This month's idea came from thinking of Microsoft's support of XML in the Office suite of products. We said to ourselves, "Heck, if Microsoft can render Word documents based on XML, we should be able to compose Word docs with RPG-XML Suite". After we worked through the issues of talking to ourselves (grin) we started pounding through what it would take to accomplish the task. In the end it turned out to be quite simple. The steps are as follows:

  1. Locate an existing Word document that you would like to create using XML. For my purposes I went out to www.microsoft.com and found an existing template which you can see at the following URL: http://tinyurl.com/yqdvc2
  2. I saved the Word template to my hard drive, opened it, then did a Save As and selected the "XML Document (*.xml)" in the "Save as type" drop-down. Name it invoice.doc. Note that I still gave it a .doc extension because I wanted Word to always open it up vs. other programs on the system. At this point you can view the new invoice in Notepad (or other text viewer) and the document’s contents will all be raw XML.
  3. Go back into your newly created invoice.doc and replace the variable data sections (i.e. [Your Company Name]) with the literal value "Your Company Name". This serves the purpose of giving us something to look for in the XML to replace with an RPG-XML Suite variable-data-placeholder (i.e. .:company_name:. or for older RXS versions /%company_name%/). Go through the entire document and replace anything with square brackets ([ and ]) with some literal text of the same name. Re-save the document, and open in Notepad to see how that affected the XML.
  4. Now that we have an instance of an XML document we are in a perfect place to create an RPG-XML Suite template. To do this I simply copied the invoice.doc file to /www/myrxs/templates/invoice.tpl on my System i5. I then modified the contents of the XML to replace what I created in step 3 to have actual RPG-XML Suite variable-data-placeholders (i.e. .:company_name:., .:invoice_number:., etc). It was also necessary to create three different sections (i.e. invoice_beg, line_item, invoice_end) so I could have repeating invoice lines. You can see the finished template file at the bottom of the following URL: NovNewsletter_MSWORD_RPG.html.
  5. At this point an RPG-XML Suite program needs to be written to fill in the data and write out the sections. You can see a concise RPG program named MSWORD at the following URL: NovNewsletter_MSWORD_RPG.html Note that values were hard coded for simplicity. The invoice.doc generated by program MSWORD can be seen at the following URL: invoice.doc.

That's all there is to it! The beautiful part about this process is your users can have full control of the Word document design. They then hand it off to you and the rest can be accomplished by following this tutorial. Stay tuned in the coming months for many more examples of how you can continue to utilize XML within your business!

This is yet another use for RPG-XML Suite that you can employ to meet your business needs and gain ROI. If you’d like to share your own practical uses of RPG-XML Suite with other RPG-XML Suite users, please email sales@krengeltech.com. We’d be happy to feature you in an upcoming newsletter!

To download a new trial of RPG-XML Suite, simply visit www.rpg-xml.com.

Copyright © 2007 Krengeltech, Inc.