// http://programmingishard.com/posts/show/356
function innerXHTML(xml, trimmed) {
	var xmlString = "";
	for(var i = 0; i < xml.childNodes.length; ++i) {
		var currentNodeName = xml.childNodes[i].nodeName;
		if(xml.childNodes[i].childNodes.length > 0) {
			xmlString += "<" + currentNodeName.toLowerCase();
			xmlString += getAttributeString(xml.childNodes[i]);
			xmlString += ">";
			xmlString += innerXHTML(xml.childNodes[i], trimmed);
			xmlString += "</" + xml.childNodes[i].nodeName.toLowerCase() + ">";						
		} else if(currentNodeName == "BR" || currentNodeName == "HR" || currentNodeName == "IMG" || currentNodeName == "DIV") {
			xmlString += "<" + currentNodeName.toLowerCase();
			xmlString += getAttributeString(xml.childNodes[i]);
			xmlString += " />";
		}
		else
			xmlString += xml.childNodes[i].nodeValue;
	}
	return (trimmed == true || trimmed == undefined) ? trim(xmlString) : xmlString;
}

function getAttributeString(element) {
	var attributeString = "";
	for(var j = 0; j < element.attributes.length; ++j) {
		if(element.attributes[j].value != "" && element.attributes[j].value != "null") {
			attributeString += " " + element.attributes[j].name;
			attributeString += "=\"" + element.attributes[j].value + "\"";
		}
	}
	return attributeString;
}

function trim(str) {
   str = str.replace(/>\s+/g, ">");
   str = str.replace(/\s+</g, "<");
   return str;
}