View Single Post
  #32  
Old 11th October 2007, 15:16
Hitesh Shah's Avatar
Hitesh Shah Hitesh Shah is offline
Guru
 
Join Date: Nov 2001
Location: Mumbai,India
Posts: 1,683
Hitesh Shah is on a distinguished road
Baan: triton,Baan IVc4 , ERP Ln - DB: Oracle/Bisam/SQL 2000/SQL 2005 - OS: Sun Solaris/Windows 2003
creating sample XML spreadsheet data list in Baan

Interoperability is the flavour of the season. Creating an interoperable scaleable xml data list which can be opened in any office spreadsheets is as easy as creating flat sequential file . Baan XML functions documented in a progguide.chm available in Baan support site. There are lot of XML samples on the board . However all the samples lead to do in-memory XML generation and parsing which is very resource intensive .

With the help of XML functions ( available in Baan XML guide ), here is the sample xml code written in Baan 4GL to create XML data lists from tccom020 without blocking substantial memory.
Code:
|******************************************************************************
|* tijwxxmltest  0  VRC B40c c4 cust
|* XML  Test
|* hitesh create test.xml data list 
|* 23-11-03 [16:36]
|******************************************************************************
|* Script Type: 0
|******************************************************************************

	table ttccom020
|****************************** DECLARATION SECTION ***************************
|****************************** PROGRAM     SECTION ***************************
|****************************** ZOOM FROM   SECTION ***************************
|****************************** FORM	     SECTION ***************************
|****************************** CHOICE      SECTION ***************************
|****************************** FIELD       SECTION ***************************
|****************************** MAIN TABLE  SECTION ***************************
|****************************** FUNCTION    SECTION ***************************

function main() 
{ 
    long mainid,rowid 
    long ret 
    long fh 
    domain    tcmcs.str80    text 
    domain    tcmcs.str80    error.msg 
	string xmlstr(1000)
    |* write 
    fh = seq.open("test.xml","w") 
    mainid = xmlNewNode("Supplier",XML_ELEMENT)
    ret=xmlWritePrettytostring(xmlstr,mainid,mainid) 
    xmlstr = xmlstr(1;len(xmlstr)-3) & ">" & chr$(10)
    if seq.puts(xmlstr,fh) then
	        message("Error writing file")
    endif
    rowid = xmlNewNode("Row",XML_ELEMENT)
    select tccom020.*
    from tccom020
    selectdo
    	xmlRewriteDataElement(rowid, "SupplierCode", tccom020.suno )
    	xmlRewriteDataElement(rowid,  "Name", tccom020.nama)    
    	xmlRewriteDataElement(rowid,  "Name2", tccom020.namb)    
    	xmlRewriteDataElement(rowid,  "Address", tccom020.namc)    
    	xmlRewriteDataElement(rowid,  "Address2", tccom020.namd)   
    	xmlstr = "" 
    	ret=xmlWritePrettytostring(xmlstr,rowid,rowid)
      	if seq.puts(xmlstr(23),fh) then
		message("Error writing file")
    	endif
    endselect
    if seq.puts("</Supplier>",fh) then
	message("Error writing file")
    endif
    seq.close(fh) 
    ret = xmlDelete(mainid) 
    ret = xmldelete(rowid)
}

The file text.xml can be opened in any office spreadsheet (including Excel) which can parse XML data files.

Probably there is still better and elegant way to create an XML file without taking the complete document in memory. At this moment its not known to me.

Last edited by george7a : 11th October 2007 at 15:44. Reason: adding baan code tags
Reply With Quote