When IE9 beta was released the first thing which our engineers did was test SiteJazzer on this new platform. As we started using SiteJazzer all the things were working fine till we came to a point where we had to save SiteJazzer. On debugging we realized that the application fails at points where we made use of “XMLSerializer”. For a short while we had posted another solution where one could use SiteJazzer in compatibility mode.
Well, finding out the solution was not a tough task for our engineers. And I would like to share that solution with all of you as well while explaining the use of DOMParser and XMLSerializer.
With IE 7 and IE 8 we used the interface “window. XMLSerializer”. As we know this interface helps to serialize the document to XML string. While using the application in IE 9 Beta it threw an exception for “XMLSerializer”. After review we found that even when Ie9 supports DOMParser and XMLSerializer, there is a change in interfaces.
Initially, IE provided support for parsing and serializing XML to and from the native DOM. But, there was no simple way for the script to access this functionality within HTML document. Now, IE 9 Beta has added more support in the DOMParser and XMLSerializer interfaces.
Here is the code for XMLSerializer which we earlier used in our web application:
if (window.XMLSerializer) {
return (new window.XMLSerializer()).serializeToString(xmlDoc);
} else if (typeof xmlDoc.xml != “undefined”) {
return xmlDoc.xml;
}
To support IE 9 Beta the code is changed as follows:
if(window.DOMParser)
{
var parser = new DOMParser();
var doc = parser.parseFromString(xmlDoc.xml, “text/xml”);
var serializer = new XMLSerializer();
var xmlString = serializer.serializeToString(doc);
return xmlString;
}
The DOMParser helps building a document from an XML string and the XMLSerializer allows you to serialize it back again. Together it makes XML to DOM conversions simple. This makes it easier to use XML as a data-transfer format in IE9.
We hope the above solution would help other developers too. Let me know if you have any queries through comments.