
function createXmlDocument(usedocument)
{
	xmlDoc = null;
	if(window.ActiveXObject)
	{
	//	alert("create active X xml");
	//	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
	}
	else if (document.implementation && document.implementation.createDocument)
	{
	//	alert("create other");
		if(usedocument == true && document !== undefined)
			return document;
		else
		{
			xmlDoc = document.implementation.createDocument("", "", null);
		}
		
	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
	return xmlDoc;
}

function parseXmlString(aString)
{
	if (window.ActiveXObject)
  	{
 	 	var doc=new ActiveXObject("Microsoft.XMLDOM");
		doc.async="false";
		doc.loadXML(aString);
  	}
	else
  	{
  		var parser=new DOMParser();
  		var doc=parser.parseFromString(aString,"text/xml");
  	}
	return doc;
}

function innerXMLGeneric (node){
	var _result = "";
	if (node == null) { return _result; }
	for (var i = 0; i < node.childNodes.length; i++) {
		var thisNode = node.childNodes[i];
		switch (thisNode.nodeType) {
			case 1: // ELEMENT_NODE
			case 5: // ENTITY_REFERENCE_NODE
				_result += getElementAsStringGeneric(thisNode);
				break;
			case 3: // TEXT_NODE
			case 2: // ATTRIBUTE_NODE
			case 4: // CDATA_SECTION_NODE
				_result += thisNode.nodeValue;
				break;
			default:
				break;
		}
	}
	return _result;	
}

function getElementAsStringGeneric (thisNode){
	var _result = "";
	if (thisNode == null) { return _result; }
	// start tag
	_result += '<' + thisNode.nodeName;
	// add attributes
	if (thisNode.attributes && thisNode.attributes.length>0) {
		for (var i = 0; i < thisNode.attributes.length; i++) {
			_result += " " + thisNode.attributes[i].name 
				+ "=\"" + thisNode.attributes[i].value + "\"";	
		}
	}
	// close start tag
	_result += '>';
	// content of tag
	_result += innerXMLGeneric(thisNode);
	// end tag
	_result += '</' + thisNode.nodeName + '>';
	return _result;
}


