XML DOM object to string conversion
Apr 22 2010 ยท javascript
One of those simple things which has eluded me for far too long. I finally found the solution here:
var string = (new XMLSerializer()).serializeToString(xmlobject);
alert(string);
While the above is good to know, I’ve also discovered I don’t need it. I was looking to convert an XML DOM object, from an AJAX call, to plain text, but the XMLHttpRequest.responseText property provides just that. For jQuery users like myself, the XMLHttpRequest can be access via a synchronous jQuery.ajax call as the return value, or asynchronously via. the jQuery.ajax.complete callback or the jQuery.ajax.success callback (as of jQuery 1.4 the XMLHttpRequest object is now the third parameter).