midrange.com code scratchpad |
Name:
Sample XMLi program
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
01/19/2011 12:13:22 am
|
IP:
Logged
|
|
Description:
This program uses XMLi to build some XML
|
Code:
- H OPTION(*NODEBUGIO:*NOEXPDDS:*SRCSTMT)
- H DFTACTGRP(*NO) ACTGRP('QILE')
-
- **************************************************************************
- * This example uses XMLi to write XML to a variable within this program.
- *
- * 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.
- *
- * This example will print the contents of the variable to the console.
- **************************************************************************
-
- // BNDDIR for XMLI1...
- H BNDDIR('XMLILIB/XMLI1')
-
- // BNDDIR for displaying example results (DO NOT USE IN PRODUCTION)
- H BNDDIR('QC2LE')
-
- **********************************************************************
- // Copybook for XMLI1...
- /include xmlilib/qrpglesrc,xmli1_h
- *********************************************************************
-
- // Program variables...
- d char1024 s 1024a
-
- d i s 10i 0
- *********************************************************************
- /free
-
- // Set the XML format to simple...
- xmli_setFormat(XML_FORMAT_SIMPLE);
-
- // Initialise the variable and tell xmli you want to write xml to it...
- char1024 = *blanks;
- xmli_useVariable(char1024);
-
- // Build some XML...
- xmli_openTag('Library');
- xmli_addAttribute('version' : 'version1.2.0');
- xmli_addAttribute('timestamp' : %char(%timestamp));
-
- // List a few categories...
- xmli_openTag('Categories');
- for i = 1 to 3;
- xmli_addElement('Category': %char(i*3));
- endfor;
- xmli_closeTag('Categories');
-
- // List a few authors...
- xmli_openTag('Authors');
- for i = 1 to 3;
- xmli_openTag('Author');
- xmli_addAttribute('index': %char(i*2));
- xmli_addData('Author Name Goes Here');
- xmli_closeTag('Author');
- endfor;
- xmli_closeTag('Authors');
-
- // List a few books...
- xmli_openTag('Books');
- for i = 1 to 3;
- xmli_openTag('Book');
- xmli_addAttribute('isbn' : %editc(i:'X'));
- xmli_openTag('Details');
- xmli_addElement('Author' : %char(i*2));
- xmli_addElement('Category' : %char(i*3));
- xmli_addElement('Blurb'
- :'Something about book ' + %editc(i:'X'));
- xmli_closeTag('Details');
- xmli_closeTag('Book');
- endfor;
- xmli_closeTag('Books');
-
- xmli_closeTag('Library');
-
- // !! 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);
-
- *INLR = *on;
- return;
-
- /end-free
|
|
|