views:

122

answers:

0

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?