Read and Write XML file?

Read and Write XML file?

Postby dutch » Fri Mar 23, 2012 4:32 am

Hi,

Have anybody know, how to read and write XML file?

Any idea, most appreciate.
Dutch
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Read and Write XML file?

Postby anserkk » Fri Mar 23, 2012 9:08 am

Try the following sample to read Xml File contents
Code: Select all  Expand view
#include "FiveWin.ch"
#include "hbxml.ch"

//--------------------//
FUNCTION Main()

    LOCAL hFile, cFileName:=""
    LOCAL oXmlDoc, oXmlIter , oXmlNode, cFieldName, cFieldData, cMemo:=""
   
    cFileName := cGetFile( "XML File (*.Xml)|*.Xml|","Select the required XML file ",curdir())
   
    If !file(cFileName)
        Return nil
    Endif
   
    hFile := FOpen( cFileName )
   
    oXmlDoc := TXmlDocument():New( hFile )
   
    IF oXmlDoc:nStatus != HBXML_STATUS_OK
        Msginfo("Error reading XML ")
        RETURN
    ENDIF
   
    oXmlIter := TXmlIterator():New( oXmlDoc:oRoot )
    oXmlNode := oXmlIter:Find()
   
    // Dumping XML Data to cMemo, Creating header
    cMemo:=Padr("FieldName",25)+Padr("FieldData",30)+CRLF
    cMemo+=Replicate("-",55)+CRLF
   
    DO WHILE oXmlNode != NIL
   
        if !empty(oXmlNode:cData)
       
            if subs(oXmlNode:cData,1,1) # "<"
                cFieldName :=oXmlNode:cName
                cFieldData:=oXmlNode:cData
            Endif
       
        else
            cFieldName := oXmlNode:cName
        endif

        oXmlNode := oXmlIter:Next() // Proceed to the next field

        // Dumpix xml data to cMemo
        cMemo += Padr(cFieldName,25)+cFieldData+CRLF        
    ENDDO
    MemoWrit("YourXMLTxt.Txt",cMemo)
   
    // Display the contents of the newly created text file
    WinExec("notepad.exe YourXMLTxt.Txt")

Return nil


Are you using an ADO Recordset ?. If so, you can easily convert your data to xml format by using the following command

Code: Select all  Expand view
oRecordset:Save( "E:\MyAppFolder\MyTest.XML", adPersistXML )


Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests