Elegant way to import XHTML nodes from xhr.responseXML into HTML document in IE?
        Posted  
        
            by Weston Ruter
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Weston Ruter
        
        
        
        Published on 2010-03-12T07:13:33Z
        Indexed on 
            2010/03/12
            7:17 UTC
        
        
        Read the original article
        Hit count: 236
        
While navigating through a site, I'm dynamically loading pages via Ajax and then only updating the elements of the page that are changed, such as the navigation state and main content area. This is similar to Lala. I am serving the site as XHTML in order to be able to have access to xhr.responseXML which I then traverse in parallel with the current document and copy the nodes over. This works very well in browsers other than IE. For IE, I have to iterate over all of the properties of each XML element I want to import into the HTML document to create it from scratch (using a function convertXMLElementToHTML()). Here's the code I'm currently using:
try {
 nodeB = document.importNode(nodeB, true);
}
catch(e){
 nodeB = nodeB.cloneNode(true);
 if(document.adoptNode)
  document.adoptNode(nodeB);
}
try {
 //This works in all browsers other than IE
 nodeA.parentNode.replaceChild(nodeB, nodeA);
}
//Manually clone the nodes into HTML; required for IE
catch(e){
 nodeA.parentNode.replaceChild(convertXMLElementToHTML(nodeB), nodeA);
}Is there a more elegant solution to mirror-translating XML nodes into HTML?
© Stack Overflow or respective owner