/*
  xmlsave

*! VERSION 2.0.0  22feb2007

*/

VERSION 10.0

INCLUDE _std_medium
INCLUDE header

HELP hlp1, view("help xmlsave")
RESET res1

DEFINE _hvwd 131
DEFINE _hvsep +135

DIALOG main, label("xmlsave - Export data to XML")			///
		tabtitle("Main")

BEGIN
  TEXT     tx_varlist  _lft        _top      _iwd        .,		///
		label("Variables:  (leave empty for all variables)")
  VARLIST  ed_varlist  @           _ss       @           .,		///
  		label("Variables")
  TEXT     tx_file     @           _ms       @           .,		///
		label("Save file as:")
  FILE     fi_file     @           _ss       @           .,		///
		error("Save file as:")					///
		label("Save as...")					///
		filter(XML (*.xml)|*.xml|All Files (*.*)|*.*)		///
		save

  GROUPBOX gb_options  @           _ls       @           _ht8,		///
		label("Options")
  GROUPBOX gb_doctype  _indent     _ms	     _cwd2       _ht4,		///
		label("Document type")
  DEFINE y @y
  RADIO    rb_dta      _indent     _ss       _inwd       .,		///
  		onclickon(script dta_on)				///
  		label("Stata DTA") 					///
  		option("doctype(dta)")					///
  		first
  RADIO    rb_excel    @     	   _ss       @	         .,		///
  		onclickon(script excel_on)				///
  		label("Excel spreadsheet")				///
  		option("doctype(excel)")				///
		last
  CHECKBOX ck_dtd      _lft2	   y         _cwd2	 ., 		///
  		label("Include Stata DTD") 				///
		option(dtd)
  CHECKBOX ck_legible  @	   _ms       @	 	 ., 		///
  		label("Use optional formatting") 			///
		option(legible)
  CHECKBOX ck_replace  @	   _ms       @	 	 ., 		///
  		label("Replace existing file") 				///
		option(replace)
END

INCLUDE ifin

SCRIPT dta_on
BEGIN
	main.ck_dtd.enable
END

SCRIPT excel_on
BEGIN
	main.ck_dtd.disable
END

PROGRAM command
BEGIN
	put "xmlsave "
	if !main.ed_varlist {
		require main.fi_file
	}
	if main.ed_varlist {
		put main.ed_varlist " "
		put "using "
		require main.fi_file
	}
	put `"""'
	put main.fi_file
	put `"" "'

	INCLUDE _ifin_pr

	beginoptions
		option main.rb_dta
		option main.rb_excel
		if main.rb_dta {
			option main.ck_dtd
		}
		option main.ck_legible
		option main.ck_replace
	endoptions
END
