/*
  xmluse

*! VERSION 1.0.0 06jan2005

*/

VERSION 9.0

INCLUDE _std_medium
INCLUDE _ht320
INCLUDE header

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

DEFINE _hvwd 131
DEFINE _hvsep +135

DIALOG main, label("xmluse - Import XML data")				///
		tabtitle("Main")

BEGIN
  TEXT     tx_file	_lft        _top      _iwd        .,		///
		label("Load file:")
  FILE     fi_file	@           _ss       @           .,		///
		error("Browse:")					///
		label("Browse...")					///
		filter(XML (*.xml)|*.xml|All Files (*.*)|*.*)

  GROUPBOX gb_options	@	    _ls       @           _ht21,	///
		label("Options")
  GROUPBOX gb_doctype	_indent     _ms	      _cwd2       _ht6,		///
		label("Document type")
  DEFINE x @x
  DEFINE y @y
  RADIO    rb_unknown	_indent     _ss       _inwd       .,		///
  		onclickon(script dta_on)				///
  		label("Unknown")					///
  		option("asdf")						///
  		first
  RADIO    rb_dta	@           _ss       @		  .,		///
  		onclickon(script dta_on)				///
  		label("Stata DTA") 					///
  		option("doctype(dta)")
  RADIO    rb_excel	@     	    _ss       @	          .,		///
  		onclickon(script excel_on)				///
  		label("Excel Spreadsheet")				///
  		option("doctype(excel)")				///
		last
  TEXT	   tx_sheet	x	    _xls      _cwd2	  .,		///
  		label("Worksheet to import:")
  EDIT 	   ed_sheet     @	    _ss	      @		  .,		///
  		option("sheet")

  TEXT	   tx_cells	@	    _ms	      @	  	  .,		///
  		label("Cell range to import:")
  EDIT 	   ed_cells     @	    _ss	      @		  .,		///
  		option("cells")
  TEXT	   tx_cells2	@	    _ss	      _ibwd 	  .,		///
  		label("Examples:  A1:J100, A20:B30, or a20:b30")

  CHECKBOX ck_datestring _lft2	    y         _cwd2	  ., 		///
  		label("Import dates as strings") 			///
		option(datestring)
  CHECKBOX ck_allstring @	    _ms       @	 	  ., 		///
  		label("Import all as strings") 				///
		option(allstring)
  CHECKBOX ck_firstrow  @	    _ms       @	 	  ., 		///
  		label("First row is variable names") 			///
		option(firstrow)
  CHECKBOX ck_missing	@	    _ms       @	 	  ., 		///
  		label("Missing values for bad data") 			///
		option(missing)
  CHECKBOX ck_nocompress @	    _ms       @	 	  ., 		///
  		label("Don't compress data") 				///
		option(nocompress)
  CHECKBOX ck_clear	@	    _ms       @	 	  ., 		///
  		label("Replace data in memory") 			///
		option(clear)
END

SCRIPT dta_on
BEGIN
	main.ck_datestring.disable
	main.ck_allstring.disable
	main.ck_missing.disable
	main.ck_nocompress.disable
	main.ck_firstrow.disable
	main.tx_sheet.disable
	main.tx_cells.disable
	main.ed_sheet.disable
	main.ed_cells.disable
	main.tx_cells2.disable
END

SCRIPT excel_on
BEGIN
	main.ck_datestring.enable
	main.ck_allstring.enable
	main.ck_missing.enable
	main.ck_nocompress.enable
	main.ck_firstrow.enable
	main.tx_sheet.enable
	main.tx_cells.enable
	main.ed_sheet.enable
	main.ed_cells.enable
	main.tx_cells2.enable
END

PROGRAM command
BEGIN
	put "xmluse "
	require main.fi_file
	put `"""'
	put main.fi_file
	put `"" "'

	beginoptions
		option main.rb_dta
		option main.rb_excel
		if main.rb_excel | main.rb_unknown {
			optionarg main.ed_sheet
			optionarg main.ed_cells
			option main.ck_firstrow
			option main.ck_allstring
			option main.ck_datestring
			option main.ck_missing
			option main.ck_nocompress
		}
		option main.ck_clear
	endoptions
END
