How do I serialize a DOM to XML text, using JavaScript, in a cross browser way?

后端 未结 1 1941
小鲜肉
小鲜肉 2020-11-27 16:06

I have an XML object (loaded using XMLHTTPRequest\'s responseXML). I have modified the object (using jQuery) and would like to store it as text in

相关标签:
1条回答
  • 2020-11-27 16:37

    You can use doc.xml in internet exlporer.

    You'll get something like this:

    function xml2Str(xmlNode) {
       try {
          // Gecko- and Webkit-based browsers (Firefox, Chrome), Opera.
          return (new XMLSerializer()).serializeToString(xmlNode);
      }
      catch (e) {
         try {
            // Internet Explorer.
            return xmlNode.xml;
         }
         catch (e) {  
            //Other browsers without XML Serializer
            alert('Xmlserializer not supported');
         }
       }
       return false;
    }
    

    Found it here.

    0 讨论(0)
提交回复
热议问题