Files
harbour-core/contrib/xhb/tests/xml1.prg
vszakats 9687850865 2013-03-16 02:10 UTC+0100 Viktor Szakats (harbour syenar.net)
* (all files)
    * stripped svn header
    * minor cleanups
    ; use following command to find out the history of files:
       git log
       git log --follow
       git blame
       git annotate
2013-03-16 02:11:42 +01:00

69 lines
1.4 KiB
Plaintext

#require "xhb"
#include "hbxml.ch"
PROCEDURE Main()
LOCAL cFile := hb_DirBase() + "test.xml"
LOCAL cString
LOCAL cNote, cDiscount
LOCAL oDoc, oBook, oIterator, oCurrent
cString := MemoRead( cFile )
IF Empty( cString )
WAIT "xml file unavailable"
RETURN
ENDIF
oDoc := TXMLDocument():New( cString, HBXML_STYLE_NOESCAPE )
IF oDoc:nError != HBXML_ERROR_NONE
WAIT "xml file parsing error " + hb_ntos( oDoc:nError )
RETURN
ENDIF
oBook := oDoc:findfirst( "book" )
IF oBook == NIL
WAIT "no books found"
RETURN
ENDIF
DO WHILE .T.
IF "id" $ oBook:aAttributes
? "book ID : " + oBook:aAttributes[ "id" ]
ELSE
? "no attribute book ID"
ENDIF
cNote := ""
cDiscount := ""
oIterator := TXMLIterator():New( oBook )
DO WHILE .T.
oCurrent := oIterator:Next()
IF oCurrent == NIL
? "end branch"
WAIT "values : " + cNote + " " + cDiscount
EXIT
ELSE
? "current tag : " + oCurrent:cName
IF oCurrent:cName == "note"
cNote := oCurrent:cData
ELSEIF oCurrent:cName == "discount"
cDiscount := oCurrent:cData
ENDIF
ENDIF
ENDDO
oBook := oDoc:findnext()
IF oBook == NIL
WAIT "no more books found"
EXIT
ENDIF
ENDDO
RETURN