* include/harbour.hbx
* fixes/changes to some function names
* config/hb_c.cfg
+ updated to do better vertical aligment in
structs, var declarations and assignments
; TODO: move this to /bin folder and add to 'install'-ed
file list, rename to 'harbour.ucf'
* src/debug/*.prg
* src/rdd/*.prg
* src/rdd/hbsix/*.prg
* src/rdd/usrrdd/rdds/*.prg
* src/rtl/*.prg
* src/vm/*.prg
* utils/hbi18n/hbi18n.prg
* utils/hbmk2/hbmk2.prg
* utils/hbmk2/examples/*.hb
* contrib/hbblat/blatcls.prg
* contrib/gtwvg/*.prg
* contrib/gtwvg/tests/*.prg
* contrib/hbblink/*.prg
* contrib/hbcairo/tests/*.prg
* contrib/hbcomm/*.prg
* contrib/hbcomm/tests/*.prg
* contrib/hbcups/tests/*.prg
* contrib/hbcurl/tests/*.prg
* contrib/hbexpat/*.prg
* contrib/hbexpat/tests/*.prg
* contrib/hbfbird/*.prg
* contrib/hbfbird/tests/*.prg
* contrib/hbfoxpro/*.prg
* contrib/hbfship/*.prg
* contrib/hbgd/*.prg
* contrib/hbgd/tests/*.prg
* contrib/hbgs/tests/*.prg
* contrib/hbhpdf/*.prg
* contrib/hbhpdf/tests/*.prg
* contrib/hbhttpd/*.prg
* contrib/hbhttpd/tests/*.prg
* contrib/hblzf/tests/*.prg
* contrib/hbmagic/tests/*.prg
* contrib/hbmisc/*.prg
* contrib/hbmisc/tests/*.prg
* contrib/hbct/*.prg
* contrib/hbct/tests/*.prg
* contrib/hbmlzo/tests/*.prg
* contrib/hbmxml/*.prg
* contrib/hbmxml/tests/*.prg
* contrib/hbmysql/*.prg
* contrib/hbmysql/tests/*.prg
* contrib/hboslib/*.prg
* contrib/hbsms/*.prg
* contrib/hbtinymt/tests/*.prg
* contrib/hbtpathy/*.prg
* contrib/hbtpathy/tests/*.prg
* contrib/hbunix/tests/*.prg
* contrib/hbxdiff/tests/*.prg
* contrib/hbzebra/tests/*.prg
* contrib/hbziparc/*.prg
* contrib/hbziparc/tests/*.prg
* contrib/rddads/*.prg
* contrib/rddads/tests/*.prg
* contrib/hbodbc/*.prg
* contrib/hbodbc/tests/*.prg
* contrib/hbpgsql/*.prg
* contrib/hbpgsql/tests/*.prg
* contrib/hbsqlit3/*.prg
* contrib/hbsqlit3/tests/*.prg
* contrib/hbwin/*.prg
* contrib/hbwin/tests/*.prg
* contrib/hbxpp/*.prg
* contrib/hbxpp/tests/*.prg
* contrib/hbxhb/*.prg
* contrib/hbxhb/tests/*.prg
* contrib/hbnetio/*.prg
* contrib/hbnetio/utils/hbnetio/*.hb
* contrib/hbnetio/utils/hbnetio/*.prg
* contrib/hbtip/*.prg
* contrib/hbtip/tests/*.prg
* tests/usrrdd/*.prg
* tests/funcarr.prg
* extras/gfspell/spell.prg
* extras/gtwvw/tests/*.prg
* extras/guestbk/*.prg
* extras/hbdoc/*.prg
* extras/rddado/*.prg
* extras/rddado/tests/*.prg
* extras/hbxlsxml/*.prg
* extras/httpsrv/*.prg
* extras/httpsrv/modules/*.prg
* extras/hbsuper/*.prg
* extras/hbvpdf/*.prg
* extras/hbvpdf/tests/*.prg
* tests/*.prg (except some which are well formatted but in different/fast-typing style)
* tests/*.hb
* bin/*.hb
* contrib/*.hb
* config/*.hb
* some manual formatting to better be able to verify
changes made by hbformat and be friendlier with hbformat.
* most files reformatted with hbformat using Maurizio's
patch, with mostly minor manual corrections and verification.
All hbformat changes for revised one-by-one.
! __DIR(): fixed to be unicode compatible
! __hbdoc_ToSource(): make sure to not generate line ending
spaces in output.
+ hbmk2/hbrun: HBMK_WITH_GTXWC built-time option to include
GTXWC. Useful for hbrun.
* hbct tests: change to not use [] as string delimiter
+ added full prototypes to Array class declaration
; NOTE: Only these were not or not fully formatted:
contrib/hbnetio/tests/*.prg
tests/hbpptest/*.prg
tests/mt/*.prg
tests/multifnc/*.prg
tests/rddtest/*.prg
utils/hbmk2/hbmk2.prg (for the most part)
src/rtl/tbrowse.prg (for the most part)
utils/hbtest/*.prg
*.ch, *.c, *.h
* src/rtl/cdpapihb.c
* src/rtl/hbadler.c
* src/rtl/hbsocket.c
* src/rtl/sha1.c
* src/vm/classes.c
* src/vm/dynsym.c
* src/vm/garbage.c
* src/debug/dbgentry.c
* do not end macros with ';' to avoid uncrustify warning
and wrong formatting as a consequence
* src/compiler/cmdcheck.c
* minor changes for uncrustify-friendliness
* contrib/hbformat/utils/hbfmtcls.prg
* contrib/hbformat/utils/hbformat.prg
% optimizations in hbformat.prg
! fixed mask/filename handling to be
multiplatform in hbformat.prg
+ added 'HBXList=' hbformat.ini parameter allowing
to add any .hbx file for proper function name
casing.
! fixed progress bar to display correctly
* tests/speedstr.prg
! fixed to run as intended in unicode code
* hbformatted
- contrib/hbwin/tests/dlg.xml
* contrib/hbwin/tests/dlg.rc
- extras/gtwvw/tests/wvwtest9.xml
+ extras/gtwvw/tests/wvwtest9.mft
* extras/gtwvw/tests/wvwtest9.rc
* renamed manifest to have .mft extension
% deleted unnecessary manifest
* "Win32 API" -> "Windows API"
! deleted CPU arch from manifest
* package/harb_win.mft
* formatting
* src/common/hbver.c
+ added version detection for win 8 and win server 2012
* minor formatting/code cleanup
* tests/gfx.prg
* updated to run in script mode.
; TOFIX: it doesn't draw anything with GTWVT
* tests/gfx.prg
* tests/gtwin.prg
* tests/gtxfnt.prg
* tests/wvt_fs.prg
* tests/wvtext.prg
+ support for GTXWC when run as script
* doc/en/*.txt
* contrib/hbct/doc/en/*.txt
* contrib/hbgd/doc/en/*.txt
* contrib/hbgt/doc/en/*.txt
* contrib/hbmisc/doc/en/*.txt
* contrib/hbnf/doc/en/*.txt
* contrib/hbziparc/doc/en/*.txt
* contrib/rddads/doc/en/*.txt
! fixed few broken tags reported by Carlos
% deleted line ending spaces
* some minor formatting
* contrib/hbnf/*.c
* contrib/hbnf/*.h
* extras/gfspell/spellc.c
* uncrustified with updated hb_c.cfg
* contrib/hbnf/*.prg
* contrib/hbnf/tests/*.prg
* hbformatted with Mauriozo's patch.
* a few manual corrections (avoiding #translates, using hb_ColorIndex())
in general and to make hbformat happy.
+ contrib/hbnf/tests/menuto.prg
+ added sample code for MENU TO (adatped from docs)
- src/rdd/dbfntx/dbfntx0.prg
- deleted unused file with no enabled code in it
* contrib/hbtip/tests/dbtohtml.prg
* contrib/hbtip/tests/loadhtml.prg
* contrib/hbtip/tests/tipmmail.prg
* minor cleanups
* contrib/hbtip/thtml.prg
! fixed typo due to s&r
% use hb_memowrit()
* src/rtl/tbrowse.prg
* conditional code sorted to be hbformat friendly
* some formatting
* INSTALL
* package/harbour.rb
* package/mpkg_src_nightly.sh
* package/mpkg_win_nightly.bat
* package/updt_web_nightly.sh
* website/changelog.html
* website/faq/harbour17.html
* website/faq/harbour27.html
* website/index.html
* website/menu/harbour-menu.js
* updated repository URL to new sf.net one
* tests/function.cfm
* contrib/hbhttpd/tests/tpl/_main.tpl
* contrib/hbtip/tests/tipmmail.prg
* website/faq/*.html
* website/samples/*.html
* use utf-8 in html and email
* contrib/hbrun/hbrun.hbp
+ support for HBMK_WITH_GTXWC
* tests/rto_get.prg
* tests/onidle.prg
* tests/mousetst.prg
* tests/wcecon.prg
* tests/vmasort.prg
- contrib/hbnf/tests/metaph.prg
* minor cleanups
* contrib/hbmysql/tests/test.prg
* contrib/hbmysql/tests/dbf2mysq.prg
% minor optimization, deleted outdated comment/line
* src/compiler/harbour.yyc
* src/compiler/harbour.y
* minor formatting
725 lines
18 KiB
Plaintext
725 lines
18 KiB
Plaintext
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Test program for Mini-XML, a small XML-like file parsing library.
|
|
*
|
|
* Copyright 2003-2011 by Michael R Sweet.
|
|
*
|
|
* These coded instructions, statements, and computer programs are the
|
|
* property of Michael R Sweet and are protected by Federal copyright
|
|
* law. Distribution and use rights are outlined in the file "COPYING"
|
|
* which should have been included with this file. If this file is
|
|
* missing or damaged, see the license at:
|
|
*
|
|
* http://www.minixml.org/
|
|
*
|
|
* Harbour port Copyright (c) 2011 Tamas TEVESZ <ice@extreme.hu>
|
|
*
|
|
*/
|
|
|
|
#require "hbmxml"
|
|
|
|
#include "hbmxml.ch"
|
|
#include "simpleio.ch"
|
|
|
|
REQUEST HB_GT_CGI_DEFAULT
|
|
|
|
STATIC s_aTypes := { ;
|
|
"MXML_ELEMENT", ;
|
|
"MXML_INTEGER", ;
|
|
"MXML_OPAQUE", ;
|
|
"MXML_REAL", ;
|
|
"MXML_TEXT" }
|
|
|
|
STATIC s_aSAXEventCounts := { 0, 0, 0, 0, 0, 0 }
|
|
|
|
/*
|
|
* 'main()' - Main entry for test program.
|
|
*/
|
|
|
|
PROCEDURE Main( cFileArg )
|
|
|
|
LOCAL hTree /* XML tree */
|
|
LOCAL hNode /* Node which should be in test.xml */
|
|
LOCAL hInd /* XML index */
|
|
LOCAL nNum, cStr
|
|
LOCAL i
|
|
|
|
/*
|
|
* Check arguments...
|
|
*/
|
|
|
|
IF Empty( cFileArg )
|
|
OutErr( "Usage: textmxml filename.xml" + hb_eol() )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
/*
|
|
* Test the basic functionality...
|
|
*/
|
|
|
|
hTree := mxmlNewElement( MXML_NO_PARENT, "element" )
|
|
IF Empty( hTree )
|
|
OutErr( "ERROR: No parent node in basic test!" + hb_eol() )
|
|
QUIT
|
|
ENDIF
|
|
|
|
nNum := mxmlGetType( hTree )
|
|
IF nNum != MXML_ELEMENT
|
|
IF nNum < MXML_ELEMENT .OR. nNum > MXML_TEXT
|
|
OutErr( hb_StrFormat( "ERROR: Parent has type %s (%d), expected MXML_ELEMENT!", ;
|
|
"UNKNOWN", nNum ) + hb_eol() )
|
|
ELSE
|
|
OutErr( hb_StrFormat( "ERROR: Parent has type %s (%d), expected MXML_ELEMENT!", ;
|
|
s_aTypes[ nNum + 1 ], nNum ) + hb_eol() )
|
|
ENDIF
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
cStr := mxmlGetElement( hTree )
|
|
IF !( cStr == "element" )
|
|
OutErr( hb_StrFormat( "ERROR: Parent value is '%s', expected 'element'", cStr ) + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlNewInteger( hTree, 123 )
|
|
mxmlNewOpaque( hTree, "opaque" )
|
|
mxmlNewReal( hTree, 123.4 )
|
|
mxmlNewText( hTree, 1, "text" )
|
|
|
|
mxmlLoadString( hTree, "<group type='string'>string string string</group>", MXML_NO_CALLBACK )
|
|
mxmlLoadString( hTree, "<group type='integer'>1 2 3</group>", MXML_INTEGER_CALLBACK )
|
|
mxmlLoadString( hTree, "<group type='real'>1.0 2.0 3.0</group>", MXML_REAL_CALLBACK )
|
|
mxmlLoadString( hTree, "<group>opaque opaque opaque</group>", MXML_OPAQUE_CALLBACK )
|
|
mxmlLoadString( hTree, "<foo><bar><one><two>value<two>value2</two></two></one></bar></foo>", MXML_OPAQUE_CALLBACK )
|
|
|
|
IF Empty( hNode := mxmlGetFirstChild( hTree ) )
|
|
OutErr( "ERROR: No first child in basic test!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
nNum := mxmlGetType( hNode )
|
|
IF nNum != MXML_INTEGER
|
|
IF nNum < MXML_ELEMENT .OR. nNum > MXML_TEXT
|
|
OutErr( hb_StrFormat( "ERROR: First child has type %s (%d), expected MXML_TEXT!", ;
|
|
"UNKNOWN", nNum ) + hb_eol() )
|
|
ELSE
|
|
OutErr( hb_StrFormat( "ERROR: First child has type %s (%d), expected MXML_TEXT!", ;
|
|
s_aTypes[ nNum + 1 ], nNum ) + hb_eol() )
|
|
ENDIF
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
nNum := mxmlGetInteger( hNode )
|
|
IF nNum != 123
|
|
OutErr( hb_StrFormat( "ERROR: First child value is %d, expected 123!", nNum ) + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
hNode := mxmlGetNextSibling( hNode )
|
|
IF Empty( hNode )
|
|
OutErr( "ERROR: No second child node in basic test!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
nNum := mxmlGetType( hNode )
|
|
IF nNum != MXML_OPAQUE
|
|
IF nNum < MXML_ELEMENT .OR. nNum > MXML_TEXT
|
|
OutErr( hb_StrFormat( "ERROR: Second child has type %s (%d), expected MXML_OPAQUE!", ;
|
|
"UNKNOWN", nNum ) + hb_eol() )
|
|
ELSE
|
|
OutErr( hb_StrFormat( "ERROR: Second child has type %s (%d), expected MXML_OPAQUE!", ;
|
|
s_aTypes[ nNum + 1 ], nNum ) + hb_eol() )
|
|
ENDIF
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
hNode := mxmlGetNextSibling( hNode )
|
|
IF Empty( hNode )
|
|
OutErr( "ERROR: No third child node in basic test!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
nNum := mxmlGetType( hNode )
|
|
IF nNum != MXML_REAL
|
|
IF nNum < MXML_ELEMENT .OR. nNum > MXML_TEXT
|
|
OutErr( hb_StrFormat( "ERROR: Third child has type %s (%d), expected MXML_REAL!", ;
|
|
"UNKNOWN", nNum ) + hb_eol() )
|
|
ELSE
|
|
OutErr( hb_StrFormat( "ERROR: Third child has type %s (%d), expected MXML_REAL!", ;
|
|
s_aTypes[ nNum + 1 ], nNum ) + hb_eol() )
|
|
ENDIF
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
nNum := mxmlGetReal( hNode )
|
|
IF nNum != 123.4
|
|
OutErr( hb_StrFormat( "ERROR: Third child value is %f, expected 123.4!", nNum ) + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
hNode := mxmlGetNextSibling( hNode )
|
|
IF Empty( hNode )
|
|
OutErr( "ERROR: No fourth child node in basic test!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
nNum := mxmlGetType( hNode )
|
|
IF nNum != MXML_TEXT
|
|
IF nNum < MXML_ELEMENT .OR. nNum > MXML_TEXT
|
|
OutErr( hb_StrFormat( "ERROR: Fourth child has type %s (%d), expected MXML_TEXT!", ;
|
|
"UNKNOWN", nNum ) + hb_eol() )
|
|
ELSE
|
|
OutErr( hb_StrFormat( "ERROR: Fourth child has type %s (%d), expected MXML_TEXT!", ;
|
|
s_aTypes[ nNum + 1 ], nNum ) + hb_eol() )
|
|
ENDIF
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
cStr := mxmlGetText( hNode, @nNum )
|
|
IF nNum != 1 .OR. Empty( cStr ) .OR. !( cStr == "text" )
|
|
OutErr( hb_StrFormat( "ERROR: Fourth child value is %d, '%s', expected 1, 'text'!", ;
|
|
nNum, cStr ) + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
FOR i := 0 TO 3
|
|
IF Empty( hNode := mxmlGetNextSibling( hNode ) )
|
|
OutErr( hb_StrFormat( "ERROR: No group #%d child node in basic test!", i ) + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF ( ( nNum := mxmlGetType( hNode ) ) != MXML_ELEMENT )
|
|
IF nNum < MXML_ELEMENT .OR. nNum > MXML_TEXT
|
|
OutErr( hb_StrFormat( "ERROR: Group child #%d has type %s (%d), expected MXML_ELEMENT!", ;
|
|
i + 1, "UNKNOWN", nNum ) + hb_eol() )
|
|
ELSE
|
|
OutErr( hb_StrFormat( "ERROR: Group child #%d has type %s (%d), expected MXML_ELEMENT!", ;
|
|
s_aTypes[ nNum + 1 ], nNum ) + hb_eol() )
|
|
ENDIF
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
NEXT
|
|
|
|
/*
|
|
* Test mxmlFindPath...
|
|
*/
|
|
|
|
hNode := mxmlFindPath( hTree, "*/two" )
|
|
IF Empty( hNode )
|
|
OutErr( "ERROR: Unable to find value for '*/two'." + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ELSEIF mxmlGetType( hNode ) != MXML_OPAQUE .OR. !( mxmlGetOpaque( hNode ) == "value" )
|
|
OutErr( "ERROR: Bad value for '*/two'." + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
hNode := mxmlFindPath( hTree, "foo/*/two" )
|
|
IF Empty( hNode )
|
|
OutErr( "ERROR: Unable to find value for 'foo/*/two'." + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ELSEIF mxmlGetType( hNode ) != MXML_OPAQUE .OR. !( mxmlGetOpaque( hNode ) == "value" )
|
|
OutErr( "ERROR: Bad value for 'foo/*/two'." + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
hNode := mxmlFindPath( hTree, "foo/bar/one/two" )
|
|
IF Empty( hNode )
|
|
OutErr( "ERROR: Unable to find value for 'foo/bar/one/two'." + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ELSEIF mxmlGetType( hNode ) != MXML_OPAQUE .OR. !( mxmlGetOpaque( hNode ) == "value" )
|
|
OutErr( "ERROR: Bad value for 'foo/bar/one/two'." + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
/*
|
|
* Test indices...
|
|
*/
|
|
|
|
hInd := mxmlIndexNew( hTree )
|
|
IF Empty( hInd )
|
|
OutErr( "ERROR: Unable to create index of all nodes!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF ( nNum := mxmlIndexGetCount( hInd ) ) != 10
|
|
OutErr( hb_StrFormat( "ERROR: Index of all nodes contains %d nodes; expected 10!", nNum ) + hb_eol() )
|
|
|
|
mxmlIndexDelete( hInd )
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlIndexReset( hInd )
|
|
IF Empty( mxmlIndexFind( hInd, "group" ) )
|
|
OutErr( "ERROR: mxmlIndexFind for 'group' failed!" + hb_eol() )
|
|
|
|
mxmlIndexDelete( hInd )
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlIndexDelete( hInd )
|
|
|
|
hInd := mxmlIndexNew( hTree, "group" )
|
|
IF Empty( hInd )
|
|
OutErr( "ERROR: Unable to create index of groups!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF ( nNum := mxmlIndexGetCount( hInd ) ) != 4
|
|
OutErr( hb_StrFormat( "ERROR: Index of groups contains %d nodes; expected 4!", nNum ) + hb_eol() )
|
|
|
|
mxmlIndexDelete( hInd )
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlIndexReset( hInd )
|
|
|
|
IF Empty( mxmlIndexEnum( hInd ) )
|
|
OutErr( "ERROR: mxmlIndexEnum failed!" + hb_eol() )
|
|
|
|
mxmlIndexDelete( hInd )
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlIndexDelete( hInd )
|
|
|
|
hInd := mxmlIndexNew( hTree,, "type" )
|
|
IF Empty( hInd )
|
|
OutErr( "ERROR: Unable to create index of type attributes!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF ( nNum := mxmlIndexGetCount( hInd ) ) != 3
|
|
OutErr( hb_StrFormat( "ERROR: Index of type attributes contains %d nodes; expected 3!", nNum ) + hb_eol() )
|
|
|
|
mxmlIndexDelete( hInd )
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlIndexReset( hInd )
|
|
IF Empty( mxmlIndexFind( hInd,, "string" ) )
|
|
OutErr( "ERROR: mxmlIndexFind for 'string' failed!" + hb_eol() )
|
|
|
|
mxmlIndexDelete( hInd )
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlIndexDelete( hInd )
|
|
|
|
hInd := mxmlIndexNew( hTree, "group", "type" )
|
|
IF Empty( hInd )
|
|
OutErr( "ERROR: Unable to create index of elements and attributes!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF ( nNum := mxmlIndexGetCount( hInd ) ) != 3
|
|
OutErr( hb_StrFormat( "ERROR: Index of type attributes contains %d nodes; expected 3!", nNum ) + hb_eol() )
|
|
|
|
mxmlIndexDelete( hInd )
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlIndexReset( hInd )
|
|
IF Empty( mxmlIndexFind( hInd, "group", "string" ) )
|
|
OutErr( "ERROR: mxmlIndexFind for 'string' failed!" + hb_eol() )
|
|
|
|
mxmlIndexDelete( hInd )
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
mxmlIndexDelete( hInd )
|
|
|
|
/*
|
|
* Check the mxmlDelete() works properly...
|
|
*/
|
|
|
|
FOR i := 0 TO 8
|
|
IF ! Empty( mxmlGetFirstChild( hTree ) )
|
|
mxmlDelete( mxmlGetFirstChild( hTree ) )
|
|
ELSE
|
|
OutErr( hb_StrFormat( "ERROR: Child pointer prematurely NULL on child #%d", i ) + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
NEXT
|
|
|
|
IF ! Empty( mxmlGetFirstChild( hTree ) )
|
|
OutErr( "ERROR: Child pointer not NULL after deleting all children!" + hb_eol() )
|
|
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF ! Empty( mxmlGetLastChild( hTree ) )
|
|
OutErr( "ERROR: Last child pointer not NULL after deleting all children!" + hb_eol() )
|
|
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
/*
|
|
* Open the file...
|
|
*/
|
|
|
|
IF Left( cFileArg, 1 ) == "<"
|
|
hTree := mxmlLoadString( NIL, cFileArg, @type_cb() )
|
|
ELSE
|
|
|
|
/*
|
|
* Read the file...
|
|
*/
|
|
|
|
hTree := mxmlLoadFile( NIL, cFileArg, @type_cb() )
|
|
ENDIF
|
|
|
|
IF Empty( hTree )
|
|
OutErr( "Unable to read XML file!" + hb_eol() )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF cFileArg == "test.xml"
|
|
|
|
/*
|
|
* Verify that mxmlFindElement() and indirectly mxmlWalkNext() work
|
|
* properly... XXX: this doesn't test for the mxmlWalkNext() _binding_
|
|
*/
|
|
|
|
IF Empty( hNode := mxmlFindElement( hTree, hTree, "choice",,, MXML_DESCEND ) )
|
|
OutErr( "Unable to find first <choice> element in XML tree!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF Empty( mxmlFindElement( hNode, hTree, "choice",,, MXML_NO_DESCEND ) )
|
|
OutErr( "Unable to find second <choice> element in XML tree!" + hb_eol() )
|
|
|
|
mxmlDelete( hTree )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
ENDIF
|
|
|
|
/*
|
|
* Print the XML tree...
|
|
*/
|
|
|
|
FErase( "out.xml" )
|
|
mxmlSaveFile( hTree, "out.xml", @whitespace_cb() )
|
|
|
|
/* XXX: */
|
|
/*
|
|
* Save the XML tree to a string and print it...
|
|
*/
|
|
|
|
cStr := Space( 16384 )
|
|
IF ( nNum := mxmlSaveString( hTree, @cStr, @whitespace_cb() ) ) > 0
|
|
OutStd( cStr + hb_eol() )
|
|
ENDIF
|
|
|
|
/*
|
|
* Delete the tree...
|
|
*/
|
|
|
|
mxmlDelete( hTree )
|
|
|
|
/*
|
|
* Test SAX methods...
|
|
*/
|
|
|
|
IF Left( cFileArg, 1 ) == "<"
|
|
mxmlSAXLoadString( NIL, cFileArg, @type_cb(), @sax_cb(), NIL )
|
|
ELSE
|
|
|
|
/*
|
|
* Read the file...
|
|
*/
|
|
|
|
mxmlSAXLoadFile( NIL, cFileArg, @type_cb(), @sax_cb(), NIL )
|
|
ENDIF
|
|
|
|
IF cFileArg == "test.xml"
|
|
|
|
IF s_aSAXEventCounts[ MXML_SAX_CDATA ] != 1
|
|
OutErr( hb_StrFormat( "MXML_SAX_CDATA seen %d times, expected 1 times!", ;
|
|
s_aSAXEventCounts[ MXML_SAX_CDATA ] ) + hb_eol() )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF s_aSAXEventCounts[ MXML_SAX_COMMENT ] != 1
|
|
OutErr( hb_StrFormat( "MXML_SAX_COMMENT seen %d times, expected 1 times!", ;
|
|
s_aSAXEventCounts[ MXML_SAX_COMMENT ] ) + hb_eol() )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF s_aSAXEventCounts[ MXML_SAX_DATA ] != 60
|
|
OutErr( hb_StrFormat( "MXML_SAX_DATA seen %d times, expected 60 times!", ;
|
|
s_aSAXEventCounts[ MXML_SAX_DATA ] ) + hb_eol() )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF s_aSAXEventCounts[ MXML_SAX_DIRECTIVE ] != 1
|
|
OutErr( hb_StrFormat( "MXML_SAX_DIRECTIVE seen %d times, expected 1 times!", ;
|
|
s_aSAXEventCounts[ MXML_SAX_DIRECTIVE ] ) + hb_eol() )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF s_aSAXEventCounts[ MXML_SAX_ELEMENT_CLOSE ] != 20
|
|
OutErr( hb_StrFormat( "MXML_SAX_ELEMENT_CLOSE seen %d times, expected 20 times!", ;
|
|
s_aSAXEventCounts[ MXML_SAX_ELEMENT_CLOSE ] ) + hb_eol() )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
IF s_aSAXEventCounts[ MXML_SAX_ELEMENT_OPEN ] != 20
|
|
OutErr( hb_StrFormat( "MXML_SAX_ELEMENT_OPEN seen %d times, expected 20 times!", ;
|
|
s_aSAXEventCounts[ MXML_SAX_ELEMENT_OPEN ] ) + hb_eol() )
|
|
ErrorLevel( 1 )
|
|
QUIT
|
|
ENDIF
|
|
|
|
ENDIF
|
|
|
|
ErrorLevel( 0 )
|
|
|
|
RETURN
|
|
|
|
/*
|
|
* 'sax_cb()' - Process nodes via SAX.
|
|
*/
|
|
|
|
/* I - Current node */
|
|
/* I - SAX event */
|
|
/* I - SAX user data */
|
|
|
|
PROCEDURE sax_cb( hNode, hEvent, hData )
|
|
|
|
/*
|
|
* This SAX callback just counts the different events.
|
|
*/
|
|
|
|
HB_SYMBOL_UNUSED( hNode )
|
|
HB_SYMBOL_UNUSED( hData )
|
|
|
|
s_aSAXEventCounts[ hEvent ]++
|
|
|
|
RETURN
|
|
|
|
/*
|
|
* 'type_cb()' - XML data type callback for mxmlLoadFile()...
|
|
*/
|
|
|
|
/* O - Data type */
|
|
/* I - Element node */
|
|
|
|
FUNCTION type_cb( hNode )
|
|
|
|
LOCAL cType /* Type string */
|
|
|
|
/*
|
|
* You can lookup attributes and/or use the element name, hierarchy, etc...
|
|
*/
|
|
|
|
IF Empty( cType := mxmlElementGetAttr( hNode, "type" ) )
|
|
cType := mxmlGetElement( hNode )
|
|
ENDIF
|
|
|
|
SWITCH Lower( cType )
|
|
CASE "integer" ; RETURN MXML_INTEGER
|
|
CASE "opaque" ; RETURN MXML_OPAQUE
|
|
CASE "real" ; RETURN MXML_REAL
|
|
ENDSWITCH
|
|
|
|
RETURN MXML_TEXT
|
|
|
|
/*
|
|
* 'whitespace_cb()' - Let the mxmlSaveFile() function know when to insert
|
|
* newlines and tabs...
|
|
*/
|
|
|
|
/* O - Whitespace string or NIL */
|
|
/* I - Element node */
|
|
/* I - Open or close tag? */
|
|
|
|
FUNCTION whitespace_cb( hNode, nWhere )
|
|
|
|
LOCAL hParent /* Parent node */
|
|
LOCAL nLevel /* Indentation level */
|
|
LOCAL cName /* Name of element */
|
|
|
|
/*
|
|
* We can conditionally break to a new line before or after any element.
|
|
* These are just common HTML elements...
|
|
*/
|
|
|
|
cName := Lower( mxmlGetElement( hNode ) )
|
|
|
|
IF cName == "html" .OR. cName == "head" .OR. cName == "body" .OR. ;
|
|
cName == "pre" .OR. cName == "p" .OR. ;
|
|
cName == "h1" .OR. cName == "h2" .OR. cName == "h3" .OR. ;
|
|
cName == "h4" .OR. cName == "h5" .OR. cName == "h6"
|
|
|
|
/*
|
|
* Newlines before open and after close...
|
|
*/
|
|
|
|
IF nWhere == MXML_WS_BEFORE_OPEN .OR. nWhere == MXML_WS_AFTER_CLOSE
|
|
RETURN hb_eol()
|
|
ENDIF
|
|
ELSEIF cName == "dl" .OR. cName == "ol" .OR. cName == "ul"
|
|
|
|
/*
|
|
* Put a newline before and after list elements...
|
|
*/
|
|
|
|
RETURN hb_eol()
|
|
ELSEIF cName == "dd" .OR. cName == "dd" .OR. cName == "li"
|
|
|
|
/*
|
|
* Put a tab before <li>s, <dd>s and <dt>s and a newline after them...
|
|
*/
|
|
|
|
IF nWhere == MXML_WS_BEFORE_OPEN
|
|
RETURN Space( 8 )
|
|
ELSEIF nWhere == MXML_WS_AFTER_CLOSE
|
|
RETURN hb_eol()
|
|
ENDIF
|
|
ELSEIF Left( cName, 4 ) == "?xml"
|
|
IF nWhere == MXML_WS_AFTER_OPEN
|
|
RETURN hb_eol()
|
|
ELSE
|
|
RETURN NIL
|
|
ENDIF
|
|
ELSEIF nWhere == MXML_WS_BEFORE_OPEN .OR. ;
|
|
( ( cName == "choice" .OR. cName == "option" ) .AND. nWhere == MXML_WS_BEFORE_CLOSE )
|
|
nLevel := -1
|
|
hParent := mxmlGetParent( hNode )
|
|
DO WHILE ! Empty( hParent )
|
|
nLevel++
|
|
hParent := mxmlGetParent( hParent )
|
|
ENDDO
|
|
|
|
IF nLevel > 8
|
|
nLevel := 8
|
|
ELSEIF nLevel < 0
|
|
nLevel := 0
|
|
ENDIF
|
|
|
|
RETURN Replicate( Chr( 9 ), nLevel )
|
|
ELSEIF nWhere == MXML_WS_AFTER_CLOSE .OR. ;
|
|
( ( cName == "group" .OR. cName == "option" .OR. cName == "choice" ) .AND. ;
|
|
nWhere == MXML_WS_AFTER_OPEN )
|
|
|
|
RETURN hb_eol()
|
|
ELSEIF nWhere == MXML_WS_AFTER_OPEN .AND. Empty( mxmlGetFirstChild( hNode ) )
|
|
RETURN hb_eol()
|
|
ENDIF
|
|
|
|
/*
|
|
* Return NULL for no added whitespace...
|
|
*/
|
|
|
|
RETURN NIL
|