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:
- H OPTION(*NODEBUGIO:*NOEXPDDS:*SRCSTMT)
- H DFTACTGRP(*NO) ACTGRP('QILE')
-
- **************************************************************************
- * This example uses XMLi to write XML to a variable within this program.
- * Once written the XML is written to the IFS from the variable.
- *
- * To use XMLi you simply tell it to use your variable and then tell it
- * what you want to write. XMLi works out where to write and how to format
- * the XML for you.
- * When you have created your XML simply tell XMLi to no longer use your
- * variable.
- *
- * The XML is written to /XMLI/Examples/Results/Example06.xml
- **************************************************************************
-
- // BNDDIR for XMLI1...
- H BNDDIR('XMLILIB/XMLI1')
- **********************************************************************
- // Copybook for XMLI1...
- /include xmlilib/qrpglesrc,xmli1_h
- *********************************************************************
-
- // Program variables...
- d char1024 s 1024a
-
- *********************************************************************
- /free
-
- // Initialise the variable and tell xmli you want to write xml to it...
- char1024 = *blanks;
- xmli_useVariable(char1024);
- xmli_setFormat(XML_FORMAT_SIMPLE);
-
- // Build some XML with entity references replacing the entities...
- xmli_openTag('Example06');
- xmli_addElement('Element1' : 'value1');
- xmli_addElement('Element2' : 'value2');
- xmli_closeTag('Example06');
-
- // !! The XML has now been written to the char1024 variable...!!
-
- // Tell XMLi you don't want it to use the variable anymore...
- xmli_freeVariable(char1024);
-
- // At this point the xml has been written to the variable by XMLi
- // and XMLi no longer references it: You are free to do whatever
- // you wish with it now. This program writes the data to a file
- // in the IFS...
- xmli_writeToFileWithVar( '/XMLI/Examples/Results/Example06.xml'
- : char1024
- : XML_ENCODING_UTF8);
-
- *INLR = *on;
- return;
-
- /end-free
|
|
|