Page 2 of 2

Re: XML for spreadsheets

Posted: Mon Jun 28, 2010 12:42 pm
by Rathinagiri
I don't think so. :) (At least for exporting)

Re: XML for spreadsheets

Posted: Mon Jun 28, 2010 3:07 pm
by sudip
Hi Rathi,

I said this because I found following line in the HMG\Harbour\ChangeLog file

Code: Select all

 ...

  * contrib/xhb/hbxml.c
There may be some functions which can handle xml nodes easily. But, I may be wrong, as I have very little (almost zero) knowledge about xml files. ;)

Thanks in advance :)

Re: XML for spreadsheets

Posted: Mon Jun 28, 2010 4:54 pm
by Rathinagiri
Yes. That is there. IMHO, that would be very much useful for retrieval from xml file than exporting.

Re: XML for spreadsheets

Posted: Tue Jun 29, 2010 4:31 am
by sudip
Yes, Rathi. You are correct :)

Actually I am searching for a better method for both read from xml file and export to xml file.

I saw some examples in other Harbour/xHarbour libraries, but yesterday I was not able to transfer them to HMG ;)

Re: XML for spreadsheets

Posted: Wed Jun 30, 2010 10:23 am
by Kana
sudip wrote:Hello All,

I want to export my data in XML format, so that it can be opened with any modern spreadsheet. Is there any easy way to do this? Or I shall write all the XML codes ...

Is there any utility which can export DBF to XML? Or Grid to XML :)

Thanks in advance :)

(After 15 minutes: IMHO, it is not very complex to write code for DBF2XML, I shall do it :) )
One of the ODBC or ADO version:

Code: Select all

Function Table2XML(oRecordSet, cTable, cFile)
  LOCAL nFields
  LOCAL nHandle
  LOCAL cBuffer
  LOCAL i:=1
  #define CRLF Chr(13)+Chr(10)
  if cFile=NIL
     cFile:="tmp.xml"
  end
  nHandle:=fCreate( cFile, 0 )
  nFields := oRecordSet:Count()-1
  DO WHILE .NOT. oRecordSet:Eof()
    cBuffer:=Space(2)+"<"+cTable+">"+CRLF
    fWrite(nHandle,cBuffer)
    FOR nField:=0 TO nFields
      cBuffer:=Space(4)+"<"+oRecordSet:Fields(nField):Name+">"//Beginning Record Tag
       DO CASE
         CASE Valtype(oRecordSet:Fields(nField):Value) == "D"
           cValue := Dtos(oRecordSet:Fields(nField):Value)
         CASE Valtype(oRecordSet:Fields(nField):Value) == "N"
           cValue := Str(oRecordSet:Fields(nField):Value)
         CASE Valtype(oRecordSet:Fields(nField):Value) == "L"
           cValue := If( oRecordSet:Fields(nField):Value, "True", "False" )
         OTHERWISE
           cValue := oRecordSet:Fields(nField):Value
       ENDCASE
       cValue:=strTran(cValue,"&","&")
       cValue:=strTran(cValue,"<","<")
       cValue:=strTran(cValue,">",">")
       cValue:=strTran(cValue,"'","&apos;")
       cValue:=strTran(cValue,["],["])
       cBuffer:=cBuffer             + ;
                Alltrim( cValue )   + ;
                "</"                + ;
                oRecordSet:Fields(nField):Name + ;
                ">"                 + ;
                CRLF
       fWrite(nHandle,cBuffer)
    NEXT nField//Ending Record Tag
    fWrite(nHandle,Space(2)+"</"+cTable+">"+CRLF)
    oRecordSet:MoveNext()
    ? ++i
  ENDDO
  oRecordSet:Close()
  fClose(nHandle)
Return nil

Re: XML for spreadsheets

Posted: Wed Jun 30, 2010 11:09 am
by swapan
sudip wrote:Hello All,

I want to export my data in XML format, so that it can be opened with any modern spreadsheet. Is there any easy way to do this? Or I shall write all the XML codes ...

Is there any utility which can export DBF to XML? Or Grid to XML :)

Thanks in advance :)

(After 15 minutes: IMHO, it is not very complex to write code for DBF2XML, I shall do it :) )
Very good initiative Sudip!

I've seen the TALLY ACCOUNTING PACKAGE (most widely used FA package in India) having the facility of importing & exporting data in XML format. If they have choosen this medium then this can be a very "happening" medium of exchange of data between two applications.

Re: XML for spreadsheets

Posted: Fri Dec 10, 2010 9:09 am
by nguyenchiduc
sudip wrote:Yes, Rathi. You are correct :)

Actually I am searching for a better method for both read from xml file and export to xml file.

I saw some examples in other Harbour/xHarbour libraries, but yesterday I was not able to transfer them to HMG ;)
Not only for XML
With any simple file structure that we know, we can use low level functions to read and write.

Sometimes for a dbf file sizes larger in PC or SQL Server, we only need to export a few fields only.

And otherwise from the XML to dbf

Depending on the purpose we will write your own functions to import/export