XML Parsing and Serializing

Parsing and serializing XML in Javascript is rarely needed: for the most part you get an XML document from an XMLHttpRequest without even asking for it. yourXHRObject.responseXML is an XML Document. That said, there are occasions at which you need to parse or serialize an XML string

var parseXML = (function() {
	return (typeof DOMParser != "undefined")
		? function( xmlString ){
			return (new DOMParser()).parseFromString(xmlString, "text/xml");
		}
		: function( xmlString ){
			var b = new ActiveXObject("Microsoft.XMLDOM");
			b.loadXML( xmlString );
			return b;
		}
})();

var serializeXML = (function() {
	return (typeof XMLSerializer != "undefined")
		? function( xmlObject ){
			return (new XMLSerializer()).serializeToString(xmlObject);
		}
		: function( xmlObject ){
			return xmlObject.xml;
		}
})();
Brotoss found the methods, Woosta wrote the wrappers. Munter helped with IE testing. You can see the tests here.