Files
harbour-core/harbour/contrib/hbmxml/tests/reminder.prg
Viktor Szakats b9fb99bd54 2011-01-12 02:03 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbmxml/hbmxml.c
    + Enabled function pointer support with new PHB_ITEM based
      callback system.
    ! MXMLSETERRORCALLBACK() fixed to reset error handler to NULL
      if wrong (or no) parameter is passed.
    ! Replaced hb_vmProc() with hb_vmSend().
    ! Fixed some missed locations still using dynsyms directly.

  * contrib/hbmxml/tests/custom.prg
  * contrib/hbmxml/tests/testmxml.prg
  * contrib/hbmxml/tests/reminder.prg
    * Switched back to use function pointers.

  * contrib/hbsqlit3/hbsqlit3.c
  * contrib/hbxdiff/hbxdiff.c
    * Renamed variables to reflect recent changes.
2011-01-12 01:04:42 +00:00

106 lines
1.9 KiB
Plaintext

/*
* $Id$
*/
#include "hbmxml.ch"
STATIC s_mxml_error := .F.
STATIC s_mxml_error_msg := ""
PROCEDURE main()
LOCAL xml
mxmlSetErrorCallback( @my_mxmlError() )
IF hb_fileExists( "rem.xml" )
xml := simplexml_load_file( "rem.xml" )
ELSE
RETURN
ENDIF
IF ! s_mxml_error
OutStd( asXML( xml ), hb_eol() )
ENDIF
mxmlDelete( xml )
IF hb_fileExists( "rem_err.xml" )
xml := simplexml_load_file( "rem_err.xml" )
IF s_mxml_error
OutErr( "hbmxml:", s_mxml_error_msg, hb_eol() )
ELSE
OutStd( asXML( xml ), hb_eol() )
ENDIF
ENDIF
RETURN
PROCEDURE my_mxmlError( cErrorMsg )
s_mxml_error_msg := cErrorMsg
s_mxml_error := .T.
RETURN
STATIC FUNCTION simplexml_load_file( file )
RETURN mxmlLoadString( NIL, hb_memoRead( file ), @type_cb() )
STATIC FUNCTION asXML( xml )
LOCAL cText := "", c
LOCAL wt := 3
LOCAL node, subnode
node := mxmlFindElement( xml, xml, "note", NIL, NIL, MXML_DESCEND )
IF Empty( node )
RETURN ""
ENDIF
subnode := mxmlGetFirstChild( node )
DO WHILE ! Empty( subnode := mxmlGetNextSibling( subnode ) )
IF mxmlGetType( subnode ) == MXML_ELEMENT
IF mxmlGetElement( subnode ) == "body"
c := mxmlGetOpaque( subnode )
ELSE
c := mxmlGetText( subnode, @wt )
ENDIF
cText += ( c + " " )
ENDIF
ENDDO
RETURN cText
FUNCTION type_cb( node )
LOCAL nResult
LOCAL cType
/* You can lookup attributes and/or use the element name, hierarchy, etc... */
IF Empty( cType := mxmlElementGetAttr( node, "type" ) )
cType := mxmlGetElement( node )
ENDIF
SWITCH Lower( cType )
CASE "note"
CASE "to"
CASE "from"
CASE "heading"
nResult := MXML_TEXT
EXIT
CASE "body"
CASE "opaque"
nResult := MXML_OPAQUE
EXIT
OTHERWISE
nResult := MXML_IGNORE
EXIT
ENDSWITCH
RETURN nResult