2010-04-28 23:00 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
+ contrib/xhb/tests/xml1.prg
+ contrib/xhb/tests/test.xml
+ Added xml test code posted to list by "Ivan re".
(after fix and formatting)
; TOFIX: This sample crashes with mingw.
This commit is contained in:
@@ -17,6 +17,13 @@
|
||||
past entries belonging to author(s): Viktor Szakats.
|
||||
*/
|
||||
|
||||
2010-04-28 23:00 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
|
||||
+ contrib/xhb/tests/xml1.prg
|
||||
+ contrib/xhb/tests/test.xml
|
||||
+ Added xml test code posted to list by "Ivan re".
|
||||
(after fix and formatting)
|
||||
; TOFIX: This sample crashes with mingw.
|
||||
|
||||
2010-04-28 19:05 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* src/rtl/Makefile
|
||||
* src/rtl/getsys.prg
|
||||
|
||||
72
harbour/contrib/xhb/tests/test.xml
Normal file
72
harbour/contrib/xhb/tests/test.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<catalog>
|
||||
<book id="bk101">
|
||||
<author>Gambardella, Matthew</author>
|
||||
<title>XML Developer's Guide
|
||||
<note>111</note>
|
||||
</title>
|
||||
<genre>Computer</genre>
|
||||
<price>44.95
|
||||
<discount>11</discount>
|
||||
</price>
|
||||
<publish_date>2000-10-01</publish_date>
|
||||
<description>An in-depth look at creating applications
|
||||
with XML.</description>
|
||||
</book>
|
||||
<book id="bk102">
|
||||
<author>Ralls, Kim</author>
|
||||
<title>Midnight Rain
|
||||
<note>222</note>
|
||||
</title>
|
||||
<genre>Fantasy</genre>
|
||||
<price>5.95
|
||||
<discount>12</discount>
|
||||
</price>
|
||||
<publish_date>2000-12-16</publish_date>
|
||||
<description>A former architect battles corporate zombies,
|
||||
an evil sorceress, and her own childhood to become queen
|
||||
of the world.</description>
|
||||
</book>
|
||||
<book id="bk103">
|
||||
<author>Corets, Eva</author>
|
||||
<title>Maeve Ascendant
|
||||
<note>333</note>
|
||||
</title>
|
||||
<genre>Fantasy</genre>
|
||||
<price>5.95
|
||||
<discount>13</discount>
|
||||
</price>
|
||||
<publish_date>2000-11-17</publish_date>
|
||||
<description>After the collapse of a nanotechnology
|
||||
society in England, the young survivors lay the
|
||||
foundation for a new society.</description>
|
||||
</book>
|
||||
<book id="bk104">
|
||||
<author>Corets, Eva</author>
|
||||
<title>Oberon's Legacy
|
||||
<note>444</note>
|
||||
</title>
|
||||
<genre>Fantasy</genre>
|
||||
<price>5.95
|
||||
<discount>14</discount>
|
||||
</price>
|
||||
<publish_date>2001-03-10</publish_date>
|
||||
<description>In post-apocalypse England, the mysterious
|
||||
agent known only as Oberon helps to create a new life
|
||||
for the inhabitants of London. Sequel to Maeve
|
||||
Ascendant.</description>
|
||||
</book>
|
||||
<book id="bk105">
|
||||
<author>Corets, Eva</author>
|
||||
<title>The Sundered Grail
|
||||
<note>555</note>
|
||||
</title>
|
||||
<genre>Fantasy</genre>
|
||||
<price>5.95
|
||||
<discount>15</discount>
|
||||
</price>
|
||||
<publish_date>2001-09-10</publish_date>
|
||||
<description>The two daughters of Maeve, half-sisters,
|
||||
battle one another for control of England. Sequel to
|
||||
Oberon's Legacy.</description>
|
||||
</book>
|
||||
</catalog>
|
||||
68
harbour/contrib/xhb/tests/xml1.prg
Normal file
68
harbour/contrib/xhb/tests/xml1.prg
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#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 NIL
|
||||
ENDIF
|
||||
|
||||
oDoc := TXmlDocument():New( cString, HBXML_STYLE_NOESCAPE )
|
||||
IF oDoc:nError != HBXML_ERROR_NONE
|
||||
WAIT "xml file parsing error " + str(oDoc:nError)
|
||||
RETURN NIL
|
||||
ENDIF
|
||||
|
||||
oBook := oDoc:findfirst( "book" )
|
||||
IF oBook == NIL
|
||||
WAIT "no books found"
|
||||
RETURN NIL
|
||||
ENDIF
|
||||
|
||||
DO WHILE .T.
|
||||
|
||||
IF HHasKey( oBook:aAttributes, "id" )
|
||||
? "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
|
||||
Reference in New Issue
Block a user