PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: Say()[Next]: Seconds2Text()
\ -> Rexx -> Inbuilt PPWIZARD Functions -> ScheduleCleanupCode()


This is an inbuilt function function provided by PPWIZARD.

The function specifies some rexx code to be executed during PPWIZARD's cleanup.

This can be used to ensure any required cleanup is performed in situations where it must be performed "or else"! Note that file deletions can be queued by the FileDelete() function.

This routine can be called any number of times and the cleanup code is executed in the order supplied. Failing code will abort the cleanup process for the rexx fragment supplied but other code will still function.

I recommend that the code be written in a defensive manner and I'd suggest that your normal processing should call the cleanup if possible and don't rely on this cleanup method (it should be a fallback). You may need to set state variables to decide on whether the cleanup code should be executed.

Note that a regina bug prevents this code from being executed if regina is killed or "Ctrl+Break" is pressed (it works for "Ctrl+C"). It should be executed for any termination such as normal, error, trap or CTRL+C etc.

The routine takes parameters as follows:

  1. The name of a macro containing rexx code.


The following code has cleanup code which must always be run otherwise problems can result.

;--- Initialization code ----------------------------------------------------
#RexxVar @@XmlCleanupRequired = 'N'
#DefineRexx 'XmlStart'
    ;--- Load what file? ----------------------------------------------------
    @@XmlFile = "{$FILE}";

    ;--- Load "w32util.dll" -------------------------------------------------
    if  RxFuncAdd('w32loadfuncs','w32util','w32loadfuncs') > 0 then
        error('Could not load "w32util", reason: ' || RxFuncErrMsg());
    call W32LoadFuncs;
    @@XmlCleanupRequired = 'Y';
    @@True  = 1;
    @@False = 0;

    ;--- Load the XML COM object --------------------------------------------
    oXML = W32CreateObject('MSXML.DOMDocument')
    if  oXML = 0 | oXML = '' then
        error('Could not create "MSXML.DOMDocument", reason: ' || W32OleGetError());

    ;--- Set some boolean properties ----------------------------------------
    @@Ignore = w32PutProperty(oXML, "ValidateOnParse",  "b", @@False)
    @@PutRc  = Rc
    @@Ignore = w32PutProperty(oXML, "Async",            "b", @@False)
    @@PutRc  = @@PutRc + Rc
    @@Ignore = w32PutProperty(oXML, "ResolveExternals", "b", @@False)
    @@PutRc  = @@PutRc + Rc
    if  @@PutRc <> 0 then
        error("Failed setting XML processing properties...");

    ;--- Load the file into the DOM -----------------------------------------
    if  FileQueryExists(@@XmlFile) = '' then
        error('The XML file "' || @@XmlFile || '" doesn''t exist!');
    @@Worked = W32CallFunc(oXML, "Load", "s", @@XmlFile);
    if  @@Worked = 0 then
        error('Failed loading the XML file "' || @@XmlFile || '"',,'Reason: ' W32OleGetError());

;--- Termination code -------------------------------------------------------
#DefineRexx 'XmlCleanup'
    if  @@XmlCleanupRequired = 'Y' then
        call W32OleCleanup
#DefineRexx ''
    ;--- Make sure we always do the cleanup code! ---------------------------
    call ScheduleCleanupCode    'XmlCleanup';

;--- Usefull macro ----------------------------------------------------------
#DefineRexx 'XmlGetXpathValue'
    @@Xpath = "{$XPATH}"
    @@oXpath = w32getsubobj(oXML, "selectSingleNode", "s", @@Xpath)
    if  Rc = 1 then
        error('Failed to find value for the XPATH "' || @@XPath || '"',, 'Reason: ' W32OleGetError());
    {$#1} = W32GetProperty(@@oXpath, "text")
    if  w32GetProperty(@@oXpath, "nodeName") = "" then
        error("XPATH FAILED: " || w32olegeterror())

;--- Now Try the code -------------------------------------------------------
#define TEST_XML_FILENAME out\TestXml.XML
    ;--- Create a simple XML file -------------------------------------------
#DefineRexx ''
    ;--- Load the simple XML we created above -------------------------------
    <$XmlStart FILE="<$TEST_XML_FILENAME>">
        ;--- Get two XML values ---------------------------------------------
        <$XmlGetXpathValue "@@ValueB" XPATH="//a/b">
        <$XmlGetXpathValue "@@ValueC" XPATH="//a/c">

        ;--- Display the values ---------------------------------------------
        call Info "VALUE B: " || @@ValueB
        call Info "VALUE C: " || @@ValueC

    ;--- Perform cleanup ----------------------------------------------------

email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: Say()[Next]: Seconds2Text()

My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am