PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: Automatically Create Chart Images[Next]: Resource Validation - Local
\ -> Examples / Tips -> Create Multiple Files From Template

Create Multiple Files From Template

This page demonstrates one way a set of data files could be created based on a template.

In this particular case multiple XML files are created for Jetform Central test data. We wish to generate quite a few variations for each basic type of form that we support.

We also wish to support the generation of XML data with real "life like" customer data as well as use of the XML field name as data (helps pinpoint errors).

We currently create about 5000 data files from about 6 templates.

The following is the contents of "JFTDATA.H" which is a common header file I will use in all similar Jetform template files:

;----------------------------------------------------------------------------
;
;    MODULE NAME:   JFTDATA.H
;
;        $Author:   USER "Dennis"  $
;      $Revision:   1.23  $
;          $Date:   04 Nov 2017 11:02:48  $
;       $Logfile:   D:/DBAREIS/Projects.PVCS/MultiOs/PPWIZARD/examples.dh.pvcs  $
;
;    DESCRIPTION:   Common include file for all test data.
;                   Tries to hide as much impementation detail as possible.
;                   This will allow us to make major changes in future
;                   without affecting user templates (if required).
;----------------------------------------------------------------------------

;--- Define Defaults --------------------------------------------------------
#define? PRINTER  PRINTR01

;--- What is the output directory? ------------------------------------------
#evaluate OutputDir ^FilePart('location', '<?OutputFile>')^



;----------------------------------------------------------------------------
;--- How to create a field --------------------------------------------------
;----------------------------------------------------------------------------
#( ''
   #define FIELD
   #ifdef USE_FIELD_NAMES_AS_DATA
           ;--- Override data supplied by using fieldname as the data ---
           <{$Name} {$FLDATTR=^xfa:match="many"^}>{$Name}</{$Name}>
   #elseif
           ;--- Use the supplied data as field data ----
           <{$Name} {$FLDATTR=^xfa:match="many"^}>{$Data}</{$Name}>
   #endif
#)


;----------------------------------------------------------------------------
;--- START XML --------------------------------------------------------------
;----------------------------------------------------------------------------
#( ''
   ;--- Define Macro --------------------------------------------------------
   #define StartJfXML

   ;--- Build filename from filename template user supplied -----------------
   #option PUSH DefineMacroReplace=ON
       ;--- Expand "parameters" ---------------------------------------------
       #define+ XML_FILE  <$XML_FILE_TEMPLATE {$?}>
   #option POP

   ;--- Output to the log file ----------------------------------------------
   Building :  "<$XML_FILE>"

   ;--- Create new test data file -------------------------------------------
   #info   "<$XML_FILE>"
   #output "<$XML_FILE>" ASIS

   ;--- Start The XML -------------------------------------------------------
   #( '<?NewLine>'
       <?xml version="1.0" encoding="UTF-8" standalone="yes"?><?NewLine>
       <!--
           <?space>         TIME: <?CompileTime>
           <?space>      MADE BY: <?=GetEnv("VCSID")>
           <?space>           ON: <?=GetEnv("COMPUTERNAME")>
           <?space>     TEMPLATE: <?InputFile>
           <?space>      VERSION: <$TEM_VERSION>
       --><?NewLine>
       <xfa:Data xmlns:xfa="http://www.xfa.com/schema/xfa-data">
       <JFXMLRecord>
   #)
#)


;----------------------------------------------------------------------------
;--- END XML ----------------------------------------------------------------
;----------------------------------------------------------------------------
#( ''
   ;--- Define Macro --------------------------------------------------------
   #define EndJfXML

   ;--- Output end of the XML (close tags) ----------------------------------
   #( '<?NewLine>'
       </JFXMLRecord>
       </xfa:Data>
   #)

   ;--- Close the file ------------------------------------------------------
   #Output
#)

The following is the contents of the first part of "REFERRAL.TEM" which is the template component for a "referral":

;----------------------------------------------------------------------------
;
;    MODULE NAME:   REF.TEM
;
;        $Author:   USER "Dennis"  $
;      $Revision:   1.23  $
;          $Date:   04 Nov 2017 11:02:48  $
;       $Logfile:   D:/DBAREIS/Projects.PVCS/MultiOs/PPWIZARD/examples.dh.pvcs  $
;
;    DESCRIPTION:   Referral test data template
;----------------------------------------------------------------------------

;--- Define VERSION number of template --------------------------------------
#define TEM_VERSION 01.299

;--- Include common test data support ---------------------------------------
#include "JFTDATA.H"

;--- Referral template ------------------------------------------------------
#define XML_FILE_TEMPLATE \
       <$OutputDir>REFERRAL_{$TYPE}_{$Jobid}_{$CodeId}_{$TSLCODE}_{$LETTERTYPECODE}.xml
#( '<?NewLine>'
   #define TdReferal

   ;--- Create the new XML file and output start of XML ---------------------
   <$StartJfXML {$?}>

   ;--- Contents of the file (starting at the JOBCARD) ----------------------
   <JF_JOB_CARD>Referral_F -agvTYPE={$TYPE} -aji{$Jobid} -advfax:NUMCOMMANDS=1 -advfax:TO_FAX_NUM_1="(03) 8615 5352" -advfax:TO_NAME_1="Eddie Chow" -advfax:OPTION_1_1=WHO:ADMINISTRATOR -z<$PRINTER></JF_JOB_CARD>
       <CODEID xfa:match="many">{$CodeId}</CODEID>
       <TSLCODE xfa:match="many">{$TSLCODE}</TSLCODE>
       <LETTERTYPECODE xfa:match="many">{$LETTERTYPECODE}</LETTERTYPECODE>
       <$Field NAME="REFERRERBRANCH"       DATA="Royal Bank Branch">
       <$Field NAME="REFERRERADDRLINE0"    DATA="156 Collins Street">
       <$Field NAME="REFERRERADDRLINE1"    DATA="Melbourne Vic 3000">
       ...
       (heaps more)
       ...
       <START xfa:dataNode="dataGroup"/>
           <LETTER_DATA></LETTER_DATA>

   ;--- Output End of XML and close the file --------------------------------
   <$EndJfXML {$?}>
#)

The following is the contents of the last part of "REFERRAL.TEM" which is creating one test file for each set up data (using the above "referral" template):

;--- Create a test file for each combination --------------------------------
#{  SET                            \
   "TYPE=F"                        \
   "JOBID=O P"                     \
   "CODEID=RAHL RAIL"              \
   "TSLCODE=24H"                   \
   "LETTERTYPECODE=LWA LNA LCP"

   ;--- Create every combination between the sets ---------------------------
   <$TdReferal TYPE="<??SET_TYPE>" Jobid="<??SET_Jobid>" CodeId="<??SET_CodeId>" TSLCODE="<??SET_TSLCODE>" LETTERTYPECODE="<??SET_LETTERTYPECODE>">
#}


;**      CommentBlock  /* (Friday 26/10/2001, 10:18:39, by Dennis Bareis) */
;**+--------------------------------------------------------------------------
;**|;--- OLD WAY ----------------------------------------------------------------
;**|<$TdReferal TYPE="F" Jobid="P" CodeId="RAHL" TSLCODE="24H" LETTERTYPECODE="LWA">
;**|       ...
;**|       (heaps more)
;**|       ...
;**|<$TdReferal TYPE="F" Jobid="O" CodeId="RAIL" TSLCODE="24H" LETTERTYPECODE="LCP">
;**+--------------------------------------------------------------------------
;**                    /* (Friday 26/10/2001, 10:18:39, by Dennis Bareis) */

The following is a sample batch file which shows the test data being created twice, once with user supplied data (to the"Field" macro) and once using the XML field names:

@echo off
cls
@echo ***
@echo *** Making ALL Referral test data (if required) ***
@echo ***

@rem *** Create test data using supplied field info ***
ppwizard ref.tem /output:out\DATA\ref.log      /dependson:-out\depends\ref_data.dep /ErrorFile:out\ref_data.err

@rem *** Create test data using XML field names ***
ppwizard ref.tem /output:out\FLD_NAMES\ref.log /dependson:-out\depends\ref_fld_names.dep /ErrorFile:out\ref_fld_names.err /Define:USE_FIELD_NAMES_AS_DATA


email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: Automatically Create Chart Images[Next]: Resource Validation - Local


PPWIZARD Manual
My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Saturday May 28 2022 at 2:55pm