TMGXMLEX ;TMG/kst/XML Exporter ;03/25/06
         ;;1.0;TMG-LIB;**1**;07/12/05

 ;"TMG XML EXPORT FUNCTION
 ;"Kevin Toppenberg MD
 ;"GNU General Public License (GPL) applies
 ;"7-12-2005

 ;"=======================================================================
 ;" API -- Public Functions.
 ;"=======================================================================

 ;"=======================================================================
 ;"PRIVATE API FUNCTIONS
 ;"=======================================================================

 ;"=======================================================================
 ;"Dependencies   (duplicates shown in parenthesies)
 ;"TMGXMLUI
 ;"--XLFSTR
 ;"--TMGDBAPI
 ;"----TMGDEBUG
 ;"------TMGUSRIF
 ;"--------(TMGDEBUG)
 ;"--------TMGSTUTL
 ;"----------(TMGDEBUG)
 ;"--------TMGXDLG
 ;"----(TMGUSRIF)
 ;"----(TMGSTUTL)
 ;"--(TMGDEBUG)
 ;"-- TMGMISC
 ;"----(TMGDBAPI)
 ;"----TMGIOUTL
 ;"----(TMGDEBUG)
 ;"----(TMGSTUTL)
 ;"TMGXMLE2
 ;"--(TMGDBAPI)
 ;"--(TMGDEBUG)
 ;"--(TMGMISC)
 ;"--(TMGUSRIF)
 ;"TMGIOUTL
 ;"--(TMGUSRIF)
 ;"--(TMGDEBUG)
 ;"--(TMGSTUTL)
 ;"--(TMGMISC)


 ;"TMGDEBUG
 ;"=======================================================================
 ;"=======================================================================


EXPORT
        ;"Purpose: To ask for parameters, select output, and do actual export

        new XMLarray
        new pArray set pArray=$name(XMLarray)
        new fileName,PriorErrorFound

        if $$UI^TMGXMLUI(pArray)=0 goto ExDone

        if (1=0) do  if fileName="" do  goto ExDone
        . write "Please select an output file for the XML export",!
        . set fileName=$$GetFName^TMGIOUTL()
        . ;"Here I need to select IO channel
        . if fileName="" quit
        . . do ShowError^TMGDEBUG(.PriorErrorFound,"No file selected, so aborting.")
        . set %ZIS("HFSNAME")=fileName
        . set %ZIS="Q" ;"queing allowed
        . set %ZIS("HFSMODE")="W"  ;"write mode
        . set IOP="HFS"
        else  do
        . write "Select device to output XML data to.",!
        . write "HFS (i.e. Host File System) will allow output to a file.",!
        . write "(A file name will be asked after HFS is chosen)."
        . set %ZIS("A")="Enter Output Device: "
        . set %ZIS("B")="HFS"

        do ^%ZIS  ;"standard device call
        if POP do  goto ExDone
        . do ShowError^TMGDEBUG(.PriorErrorFound,"Error opening output file.  Aborting.")
        use IO

        do WriteXMLData^TMGXMLE2(pArray,,,1)
        do ^%ZISC ;" Close the output device

        write !,"(Data written to ouput file)",!

ExDone
        kill TMGXDEBUG
        write !,"Leaving XML Exporter.  Goodbye.",!
        quit
