www.krengeltech.com

RXS BLDTPL

From Wiki

BLDTPL (Build XML Template)

User Guide

The BLDTPL command aids the composing of RPG-XML Suite template (*.tpl) files which are used in conjunction with the Template Engine to compose XML documents. Composing the necessary XML for the *.tpl files can become quite laborious and typing errors can cause wasted time debugging trying to figure why your program is not working as expected. BLDTPL aims to alleviate those problems and make you more productive.

BLDTPL usage can best be explained with an example. The first thing needed is an XML document residing in the IFS. Type the following on the command line to create an XML file named /home/bldtpl001.xml in the IFS.


    QSH CMD('touch -C 819 /home/bldtpl001.xml')


The file now exists but without content. To add content we will use the EDTF command and copy/paste the following XML into the EDTF editor.


    EDTF '/home/bldtpl001.xml'


Add the following XML to the file:

  <PostAdr residential="true">
    <name title="Mr.">
      <first>Aaron</first>
      <last>Bartell</last>
    </name>
    <street>123 Center Rd</street>
    <cty>Mankato</cty>
    <state>MN</state>
    <zip>56001</zip>
    <phone>123-123-1234</phone>
    <phone>321-321-4321</phone>
  </PostAdr>

While in the Edit File editor select F2 to save the document changes. Now it is time to invoke the BLDTPL command to generate a *.tpl file that will facilitate composing the PostAdr XML document.


  BLDTPL 
    IFSXMLLOC('/home/bldtpl001.xml')
    IFSTPLLOC('/www/myrxs/templates/bldtpl001.tpl') 
    INDENT(2)


The IFSXMLLOC parameter is the location of the XML file that was created in the above steps. The IFSTPLLOC is where we want the new bldtpl001.tpl file to be located – place it in the location of all other RPG-XML Suite templates. The last parameter, INDENT, allows you to specify how the template’s XML should be indented. Note that indenting is purely for ease of editing.

See below for the resulting template file located at /www/myrxs/templates/bldtpl001.tpl. Note that all elements and attributes have had their values replaced with variable place holders (i.e. .:variable:.) respective to the element or attributes name. This file is now ready to be used by the RPG-XML Suite Template Engine. Note that you would reference the file bldtpl001.tpl on the RXS_loadTpl subprocedure (i.e. RXS_loadTpl(‘bldtpl001.tpl’) ).


  <PostAdr residential=".:residential:.">
    <name title=".:title:.">
      <first>.:first:.</first>
      <last>.:last:.</last>
    </name>
    <street>.:street:.</street>
    <cty>.:cty:.</cty>
    <state>.:state:.</state>
    <zip>.:zip:.</zip>
    <phone>.:phone:.</phone>
  </PostAdr>


One last thing to note is that in file bldtpl001.xml there were two <phone> elements. Whenever the BLDTPL command comes across the same XPath (i.e. ‘/PostAdr/phone’ in this case) it will not process it a second time. It will instead assume the <phone> tag will most likely be in its own section (maybe named ::phone). By putting the <phone> tag in its own section you have modularized the template file and now many <phone> tags can be easily written out in the transaction file by wrapping it with a DOW loop.

Once the BLDTPL process is complete you will need to add your sections. Below is an example of how bldtpl001.tpl has been modified with sections.


  ::PostAdr_beg
  <PostAdr residential=".:residential:.">
    <name title=".:title:.">
      <first>.:first:.</first>
      <last>.:last:.</last>
    </name>
    <street>.:street:.</street>
    <cty>.:cty:.</cty>
    <state>.:state:.</state>
    <zip>.:zip:.</zip>
  ::phone
    <phone>.:phone:.</phone>
  ::PostAdr_end
  </PostAdr>