<March 2008>
SuMoTuWeThFrSa
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

Navigation

Subscriptions

Simple XML Generation without the Report

Most of you should be aware of our Advanced Report Generation templates that were introduced in Clarion 6. There is Report to HTML, Report to PDF, Report to Text, and Report to XML.

Quite often we receive requests asking for a simple way to create XML documents, developers looking to programatically create XML docs without using the Report procedure.

One of our developers, Diego Borojovich, shows you here how easy this is to do using the XMLGenerator class.

PROGRAM
 MAP
 END

 INCLUDE('ABPRXML.INC'),ONCE

XML XMLGenerator !create an instance of the
XMLGenerator class

 CODE
  XML.Init('breakfast_menu.XML')
  XML.OpenDocument()
  XML.SetEncoding('ISO-8859-1')
  XML.XMLVersion = '1.0'
  XML.SetRootTag('breakfast_menu')
  XML.AddComment('The root tag is the first tag in the doc')
  XML.AddTag('food','')
  XML.AddAttribute('recordNumber','1','food')
  XML.AddTag('name','Belgian Waffles',false,'food')
  XML.AddTag('price','$5.95',false,'food')
  XML.AddTag('description','two of our famous Belgian Waffles with plenty of real maple syrup',false,'food')
  XML.AddTag('calories','650',false,'food')
  XML.AddTag('food','')
  XML.AddAttribute('recordNumber','2','food')
  XML.AddTag('name','Strawberry Belgian Waffles',false,'food')
  XML.AddTag('price','$7.95',false,'food')
  XML.AddTag('description','light Belgian waffles covered with strawberries and whipped cream',false,'food')
  XML.AddTag('calories','900',false,'food')
  XML.CloseDocument()

*****************************
Here are the xml elements created by the program:

<breakfast_menu>
    <food recordNumber="1">
       <name>gt;Belgian Waffles</name>
       <price>$5.95</price>
       <description>
       two of our famous Belgian Waffles with plenty of real maple syrup
       </description>
       <calories>650</calories>
    </food>
    <food recordNumber="2">
       <name>Strawberry Belgian Waffles</name>
       <price>$7.95</price>
       <description>
       light Belgian waffles covered with strawberries and whipped cream
       </description>
       <calories>900</calories>
    </food>
</breakfast_menu>


That's all there is to it. We're working on adding some additional documentation for this class, but in the mean time if you examine the parameter names of each of the methods, the class is nearly self-documenting.

We have a new XML reader class for C7 that will read any sized XML file very quickly and is super easy to use -- and is pure Clarion code. Stay tuned for more info, and now I'm going bowling!

posted on Friday, March 07, 2008 1:20 PM by Bob Foreman

Powered by Community Server, by Telligent Systems