[removed] Replacement for XMLSerializer.serializeToString()?

前端 未结 4 1137
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 03:50

I\'m developing a website using the Seam framework and the RichFaces AJAX library (these isn\'t really all that important to the problem at hand - just some background).

4条回答
  •  离开以前
    2020-12-10 04:39

    In IE you can simply use the xml property of the XML node, provided newnode really is an XML node rather than an HTML node:

    function serializeXmlNode(xmlNode) {
        if (typeof window.XMLSerializer != "undefined") {
            return (new window.XMLSerializer()).serializeToString(xmlNode);
        } else if (typeof xmlNode.xml != "undefined") {
            return xmlNode.xml;
        }
        return "";
    }
    
    oldnode.outerHTML = serializeXmlNode(newnode);
    

    Update following question update

    I wouldn't use outerHTML to replace an element. It's not universally supported. Instead, you could use a mix of innerHTML and standard DOM methods as follows:

    var tempEl = document.createElement("div");
    tempEl.innerHTML = serializeXmlNode(newnode);
    oldnode.parentNode.replaceChild(oldnode, tempEl.firstChild);
    

提交回复
热议问题