function xmlToJSON(xmlString) {
		var tokens = [];
		var currToken = '';
		var i = 0;

		xmlString = cleanXml(xmlString);

		if (!xmlString || '' ===  xmlString) {
			return {};
		}

		if (!validateXML(xmlString)) {
			throw ("Error - XML is invalid");
		}

		tokens = tokenizeXML(xmlString);		

		// reset scope for this parsing run
		resetGlobalScope();
		scopeDown(tokens[0]);

		// Reset the json output object for this parsing run
		json = {};
		json[getTagName(tokens[0])] = createObjectFromTag(tokens[0]);

		// Parse the xml tree via the tokens
		for (i = 1; i < tokens.length; i++) {
			currToken = tokens[i];
			if (isOpenTag(currToken)) {
				addObjectAtCurrentScope(currToken, json);
				scopeDown(currToken)
			}
			else if (isCloseTag(currToken)) {
				scopeUp();
			}
			else if (isEmptyTag(currToken)) {
				addObjectAtCurrentScope(currToken, json);
			}
			else if (isValue(currToken)) {
				addValueAtCurrentScope(currToken, json);
			}
			else {
				throw "Invalid token found: " + currToken;
			}
		}
		
		return json;
	}
/*
	*	Parses an xml string into a JSON object
	*	@param {String} xmlString - A properly formed xml string
	*	@return {object} - The xml string represented in a JavaScript object
	*/
Parses an xml string into a JSON object
@param {String} xmlString - A properly formed xml string
@return {object} - The xml string represented in a JavaScript object
Parses an xml string into a JSON object @param { String } xmlString - A properly formed xml string @return { object } - The xml string represented in a JavaScript object
function xmlToJSON(xmlString) {
		var tokens = [];
		var currToken = '';
		var i = 0;
		xmlString = cleanXml(xmlString);
		if (!xmlString || '' ===  xmlString) {
			return {};
		}
		if (!validateXML(xmlString)) {
			throw ("Error - XML is invalid");
		}
		tokens = tokenizeXML(xmlString);		
		resetGlobalScope();
		scopeDown(tokens[0]);
		json = {};
		json[getTagName(tokens[0])] = createObjectFromTag(tokens[0]);
		for (i = 1; i < tokens.length; i++) {
			currToken = tokens[i];
			if (isOpenTag(currToken)) {
				addObjectAtCurrentScope(currToken, json);
				scopeDown(currToken)
			}
			else if (isCloseTag(currToken)) {
				scopeUp();
			}
			else if (isEmptyTag(currToken)) {
				addObjectAtCurrentScope(currToken, json);
			}
			else if (isValue(currToken)) {
				addValueAtCurrentScope(currToken, json);
			}
			else {
				throw "Invalid token found: " + currToken;
			}
		}
		return json;
	}
function xmlToJSON ( xmlString ) { var tokens = [ ] ; var currToken = '' ; var i = 0 ; xmlString = cleanXml ( xmlString ) ; if ( ! xmlString || '' === xmlString ) { return { } ; } if ( ! validateXML ( xmlString ) ) { throw ( "Error - XML is invalid" ) ; } tokens = tokenizeXML ( xmlString ) ; resetGlobalScope ( ) ; scopeDown ( tokens [ 0 ] ) ; json = { } ; json [ getTagName ( tokens [ 0 ] ) ] = createObjectFromTag ( tokens [ 0 ] ) ; for ( i = 1 ; i < tokens . length ; i ++ ) { currToken = tokens [ i ] ; if ( isOpenTag ( currToken ) ) { addObjectAtCurrentScope ( currToken , json ) ; scopeDown ( currToken ) } else if ( isCloseTag ( currToken ) ) { scopeUp ( ) ; } else if ( isEmptyTag ( currToken ) ) { addObjectAtCurrentScope ( currToken , json ) ; } else if ( isValue ( currToken ) ) { addValueAtCurrentScope ( currToken , json ) ; } else { throw "Invalid token found: " + currToken ; } } return json ; }
Parses an xml string into a JSON object
       @param {String} xmlString - A properly formed xml string
       @return {object} - The xml string represented in a JavaScript object
Parses an xml string into a JSON object @param { String } xmlString - A properly formed xml string @return { object } - The xml string represented in a JavaScript object
// reset scope for this parsing run // Reset the json output object for this parsing run // Parse the xml tree via the tokens