Hi,
Have anybody know, how to read and write XML file?
Any idea, most appreciate.
Dutch
#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
oRecordset:Save( "E:\MyAppFolder\MyTest.XML", adPersistXML )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 60 guests