× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




Hi guys,

I have finally released a Beta version of my updated xml generation tools, XMLi.

It should be found here: http://sourceforge.net/projects/xmli/

To give you an idea there are two ways to build xml using this tool:

- first way is to build the xml using the provided procedures in XMLi1

Code looks like this:

// Set variables to use...
elem2 = 'hello!';
elem4 = 'This is a long piece of text in a longer field.';

// Tell XMLi where you want to write the xml...
xmli_useVariable(myVariable);

// Build xml on myVariable...
xmli_addDeclaration(819 : XML_STANDALONE_YES);
xmli_openTag('root');
xmli_addAttribute('dateTime' : %char(%timespamp():*ISO));

xmli_addElement('element1' : 'a value here');
xmli_addElement('element2' : elem2);
xmli_addElement('element3' : %char(%date():*ISO));
xmli_addElement('element4' : elem4);
xmli_addElement('element5' : %char(126.78));

chain ('ORDER1') xmliorders;
if %found(xmliorders);
xmli_addElement('OrderNumber' : ORDORDNO);
xmli_addElement('OrderDate' : %char(ORDDAT:*EUR));
xmli_addElement('OrderTotal' : '$' + %char(ORDTOT));
xmli_addElement('OrderCust' : ORRDCUS);
endif;

xmli_closeTag('root');

xmli_freeVariable(myVariable);

Here
you tell xmli where you want the xml to be written (xmli_useVariable()) and
then just build it using the provided procedures. You can write it to the IFS using the writeToFile() and/or appendToFile() procedures.

This method also works with pointers. In fact, it provides an internally handled pointer so you don't have to deal with them and write large xml with it. Further, you can use up to 255 variables / pointers simultaneously. They can even be in different programs. this is to allow you to build standard routines for things like address details, invoice information, and then just call them when needed. The xml they write can be on a variable or pointer in another program, or they can be in a variable that can have the xml fragment added to the 'main' fragment later.

Examples are provided in the zip file along with a word doc detailing the technique.

This method is used in production in one company to build xml in RPG programs to be served to the internet via JSP. It is extremely fast and supports over 50% of all sales for the business.



- second way is to use a xml template and execute the build using XMLi2 - the templates can take parameters, define variables, run SQL statements (even nested) and CL commands. The looping around the SQL results support leave and iter. You can import other templates, again to support standard address or invoice templates within more complicated templates. The SQL even supports SYS or SQL naming conventions - it is an attribute of the temaplte (see below). This can be overridden on a per-statement level. As you can see, the SQL also supports parameter markers - in this case a program variable was passed to the template and used as a parameter to the SQL.

Just to point out - the RPG has 3 xml-related lines of code! All of the work is done in the template. Changing the xml is a case of changing the template and re-running the program.

This method is used in a company which have templates using multiple imports and over 30 SQL statements (running in a single template!). The customer-facing documentation is built using xml stylesheets over xml generated from RPG application code using this tool. This tool uses XMLi1 (above) to build the xml for it.

RPG Code looks like:

// load the template from the IFS...
xmli_loadTemplate(templateName : templateLocationInIFS);

// set template parameter 1 to the order number...
xmli_setParm(1 : %trim(orderNumber));

// run the template...
xmli_runTemplate();

Template looks like:

<xmli-template xmlns:xmli="http://www.sourceforge.net/xmli"; sql-naming="SQL" ccsid="819" >

<!-- This example runs a SQL statement and builds XML from the results -->
<!-- The first template parameter is a customer number and will be used in the SQL -->
<!-- The xmli:with-parm element specifies the value to be used by SQL in place of the ? -->
<!-- The order in which the xmli:with-parm elements are written should match the order of ? in the SQL statement -->

<root>
<!-- Run SQL to get a list of Orders by order number (sql-naming is set to SQL) -->
<xmli:run-sql name="orders" statement="select ordordno, orddat, ordtot, ordcus
from xmlilib.xmliorders
where ordcus = ?
order by ordordno">
<xmli:with-parm type="*CHAR" select="{$parm[1]}" />
</xmli:run-sql>

<!-- For each row found, write the XML -->
<!-- Note: Here only orders for CUSTOMER1 (in parm[1]) will be written -->
<!-- That is, only ORDER1 and ORDER3 should be included in the XML -->
<xmli:for-each>
<order>
<OrderNumber><xmli:value-of select="{$orders.1}" /></OrderNumber>
<OrderDate><xmli:value-of select="{$orders.2}" /></OrderDate>
<OrderTotal>$<xmli:value-of select="{$orders.3}" /></OrderTotal>
<OrderCustomer><xmli:value-of select="{$orders.4}" /></OrderCustomer>
</order>

<!-- Run SQL to get a list of lines for each order retrieved -->
<!-- Note: the current value of $orders.1 is used to run this SQL statement -->
<xmli:run-sql name="lines" statement="select linlinno, linitem, linqty, lintot
from xmlilib.xmlilines
where linordno = ?
order by linlinno">
<xmli:with-parm type="*CHAR" select="{$orders.1}" />
</xmli:run-sql>

<xmli:for-each>
<line>
<LineNumber><xmli:value-of select="{$lines.1}" /></LineNumber>
<LineItem><xmli:value-of select="{$lines.2}" /></LineItem>
<LineQty><xmli:value-of select="{$lines.3}" /></LineQty>
<LineTotal>$<xmli:value-of select="{$lines.4}" /></LineTotal>
</line>
</xmli:for-each>

</xmli:for-each>
</root>

<!-- The result is written to the IFS in the path specified (the path could be a parameter) -->
<xmli:write-to-file path="/XMLi/Examples/Results/Example15.xml" />
</xmli-template>

I encourage you all to download and at least read the docs in the zip file. Even better would be if you could try the examples in the QRPGLESRC file in the XMLILIB. They either print XML to the console or to the IFS. There are examples of both types of xml generation. There is a set of tables in the library with limited data for you to test with. I have used a couple in the example above.

Cheers, and have fun!

Larry Ducie


_________________________________________________________________
View photos of singles in your area! Browse profiles for FREE
http://clk.atdmt.com/NMN/go/150855801/direct/01/

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.