Converting an XML DOM Object to a String Using JavaScript

This is actually very simple, but it took a bit to discover so I’m posting it to address that.

function getXmlAsString(xmlDomObj){
   return (typeof XMLSerializer!=="undefined") ?
      (new XMLSerializer()).serializeToString(xmlDomObj) :
      xmlDomObj.xml;
}

Leave a Reply

Your email address will not be published. Required fields are marked *