midrange.com code scratchpad
Name:
Sample XMLi program writing to IFS
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
01/19/2011 12:15:32 am
IP:
Logged
Description:
This program uses XMLi to create XML and then writes it to a streamfile
Code:
  1.      H OPTION(*NODEBUGIO:*NOEXPDDS:*SRCSTMT)
  2.      H DFTACTGRP(*NO) ACTGRP('QILE')
  3.  
  4.       **************************************************************************
  5.       * This example uses XMLi to write XML to a variable within this program.
  6.       * Once written the XML is written to the IFS from the variable.
  7.       *
  8.       * To use XMLi you simply tell it to use your variable and then tell it
  9.       * what you want to write. XMLi works out where to write and how to format
  10.       * the XML for you.
  11.       * When you have created your XML simply tell XMLi to no longer use your
  12.       * variable.
  13.       *
  14.       * The XML is written to /XMLI/Examples/Results/Example06.xml
  15.       **************************************************************************
  16.  
  17.       // BNDDIR for XMLI1...
  18.      H BNDDIR('XMLILIB/XMLI1')
  19.       **********************************************************************
  20.       // Copybook for XMLI1...
  21.       /include xmlilib/qrpglesrc,xmli1_h
  22.       *********************************************************************
  23.  
  24.       // Program variables...
  25.      d char1024        s           1024a
  26.  
  27.       *********************************************************************
  28.       /free
  29.  
  30.        // Initialise the variable and tell xmli you want to write xml to it...
  31.        char1024 = *blanks;
  32.        xmli_useVariable(char1024);
  33.        xmli_setFormat(XML_FORMAT_SIMPLE);
  34.  
  35.        // Build some XML with entity references replacing the entities...
  36.        xmli_openTag('Example06');
  37.          xmli_addElement('Element1' : 'value1');
  38.          xmli_addElement('Element2' : 'value2');
  39.        xmli_closeTag('Example06');
  40.  
  41.        // !! The XML has now been written to the char1024 variable...!!
  42.  
  43.        // Tell XMLi you don't want it to use the variable anymore...
  44.        xmli_freeVariable(char1024);
  45.  
  46.        // At this point the xml has been written to the variable by XMLi
  47.        // and XMLi no longer references it: You are free to do whatever
  48.        // you wish with it now. This program writes the data to a file
  49.        // in the IFS...
  50.        xmli_writeToFileWithVar( '/XMLI/Examples/Results/Example06.xml'
  51.                               : char1024
  52.                               : XML_ENCODING_UTF8);
  53.  
  54.        *INLR = *on;
  55.        return;
  56.  
  57.       /end-free 
© 2004-2019 by midrange.com generated in 0.005s valid xhtml & css