lib/xvnode.js
function serialize(node, indent) {
	indent = indent || 0;
	var type = node._type;
	var v;
	if (type < 3 || type == 7) {
		var name = node.name();
		if (type == 1) {
			var children = node;
			var ret = "";
			var attrs = "";
			var hasChildNodes = false;
			children.forEach(function (child, i) {
				var type = child._type;
				if (type == 2) {
					attrs += " " + serialize(child);
				} else {
					if (type == 1) hasChildNodes = hasChildNodes || true;
					ret += serialize(child, indent + 1);
				}
			});
			var dent = "";
			for (var i = 0; i < indent; i++) {
				dent += "\t";
			}
			return "\n" + dent + "<" + name + attrs + (ret === "" ? "/>" : ">") + ret + (ret === "" ? "" : (hasChildNodes ? "\n" + dent : "") + "</" + name + ">");
		} else if (type == 7) {
			v = node.value();
			return "<?" + name + " " + v.replace(/&/g, "&amp;") + "?>";
		} else {
			v = node.value();
			return name + "=\"" + v.replace(/&/g, "&amp;") + "\"";
		}
	} else if (type == 3 || type == 4 || type == 7 || type == 8) {
		v = node.value();
		if (type == 4) {
			return "<![CDATA[" + v + "]]>";
		} else if (type == 8) {
			return "<!--" + v + "-->";
		} else {
			return v.replace(/&/g, "&amp;");
		}
	} else {
		return "";
	}
}
function serialize(node, indent) {
	indent = indent || 0;
	var type = node._type;
	var v;
	if (type < 3 || type == 7) {
		var name = node.name();
		if (type == 1) {
			var children = node;
			var ret = "";
			var attrs = "";
			var hasChildNodes = false;
			children.forEach(function (child, i) {
				var type = child._type;
				if (type == 2) {
					attrs += " " + serialize(child);
				} else {
					if (type == 1) hasChildNodes = hasChildNodes || true;
					ret += serialize(child, indent + 1);
				}
			});
			var dent = "";
			for (var i = 0; i < indent; i++) {
				dent += "\t";
			}
			return "\n" + dent + "<" + name + attrs + (ret === "" ? "/>" : ">") + ret + (ret === "" ? "" : (hasChildNodes ? "\n" + dent : "") + "</" + name + ">");
		} else if (type == 7) {
			v = node.value();
			return "<?" + name + " " + v.replace(/&/g, "&amp;") + "?>";
		} else {
			v = node.value();
			return name + "=\"" + v.replace(/&/g, "&amp;") + "\"";
		}
	} else if (type == 3 || type == 4 || type == 7 || type == 8) {
		v = node.value();
		if (type == 4) {
			return "<![CDATA[" + v + "]]>";
		} else if (type == 8) {
			return "<!--" + v + "-->";
		} else {
			return v.replace(/&/g, "&amp;");
		}
	} else {
		return "";
	}
}
function serialize ( node , indent ) { indent = indent || 0 ; var type = node . _type ; var v ; if ( type < 3 || type == 7 ) { var name = node . name ( ) ; if ( type == 1 ) { var children = node ; var ret = "" ; var attrs = "" ; var hasChildNodes = false ; children . forEach ( function ( child , i ) { var type = child . _type ; if ( type == 2 ) { attrs += " " + serialize ( child ) ; } else { if ( type == 1 ) hasChildNodes = hasChildNodes || true ; ret += serialize ( child , indent + 1 ) ; } } ) ; var dent = "" ; for ( var i = 0 ; i < indent ; i ++ ) { dent += "\t" ; } return "\n" + dent + "<" + name + attrs + ( ret === "" ? "/>" : ">" ) + ret + ( ret === "" ? "" : ( hasChildNodes ? "\n" + dent : "" ) + "</" + name + ">" ) ; } else if ( type == 7 ) { v = node . value ( ) ; return "<?" + name + " " + v . replace ( / & / g , "&amp;" ) + "?>" ; } else { v = node . value ( ) ; return name + "=\"" + v . replace ( / & / g , "&amp;" ) + "\"" ; } } else if ( type == 3 || type == 4 || type == 7 || type == 8 ) { v = node . value ( ) ; if ( type == 4 ) { return "<![CDATA[" + v + "]]>" ; } else if ( type == 8 ) { return "<!--" + v + "-->" ; } else { return v . replace ( / & / g , "&amp;" ) ; } } else { return "" ; } }
children is a no-op because it's equal to the node
children is a no - op because it s equal to the node