<?xml version="1.0"?>
<package xmlns="Windows Scripting Host">

<job>
<comment>
	Simple script to read in a  text file and then wrap it in an xml tag so xslt
	can insert the data
	
	Requirements:
		WSH 5+
		File System Object

</comment>

<object id="objFSO" progid="Scripting.FileSystemObject"/>

<resource id="errMessage">
Incorrect Usage.
	cscript //nologo file.to.xml.wsf /file=file.txt
</resource>

<script language="JScript">
<![CDATA[

	//	Create Global CDATA strings for XML compliance from Unicode character values.
	var strOpenCDATA = String.fromCharCode(60,33,91,67,68,65,84,65,91);
	var strCloseCDATA = String.fromCharCode(93,93,62);
	var strCRLF = String.fromCharCode(13,10);

	function wrapFile(strFile) {
		var objTextFile = objFSO.OpenTextFile(strFile);
		var strReturn = '';
		
		strReturn += '<?xml version="1.0" encoding="ISO-8859-1"?>' + strCRLF;
		strReturn += '<TextFile>' + strCRLF;
		strReturn += strOpenCDATA + strCRLF;
		strReturn += objTextFile.ReadAll() + strCRLF;
		strReturn += strCloseCDATA + strCRLF;
		strReturn += '</TextFile>';
		
		return(strReturn);
		delete objTextFile;
	}
	
	function cleanUp() {
		delete objFSO;
	}

	function action() {
		var strAction='', strFile='';
		//	Get command line arguments
		var objArgs = WScript.Arguments;
				
		//	Go throught the command line to check for valid paramaters
		for (var i = 0; i < objArgs.length; i++) {
			var arrArg = objArgs.Item(i).split('=');
			switch (arrArg[0]){
				case '/file':
					strFile = arrArg[1];
					break;
				default:
					strAction = 'error';				
			}
			delete arrArg;
		}
		
		if ( strAction == 'error' | strFile=='') {
			//	Incorrent argument so display error
			WScript.Echo(getResource('errMessage'));
		}
		else {
			//	Run wrapFile
			WScript.Echo(wrapFile(strFile));
		}
		
		cleanUp();
	}

	action();

]]>
</script>
</job>

</package>