Trouble with loadXML from string

Hi, I got some trouble parsing an XML response from a string in IExplorer. The javascript code that does the parsing looks like this:

[code]
if (typeof DOMParser == "undefined") {
DOMParser = function () {}
DOMParser.prototype.parseFromString = function (str, contentType) {
if (typeof ActiveXObject != "undefined") {
var d = new ActiveXObject("Microsoft.XMLDOM");
d.async="false";
d.loadXML(str);
return d;
} else if (typeof XMLHttpRequest != "undefined") {
var req = new XMLHttpRequest;
req.open("GET", "data:" + (contentType || "application/xml") +";charset=utf-8," + encodeURIComponent(str), false);
if (req.overrideMimeType) {
req.overrideMimeType(contentType);
}
req.send(null);
return req.responseXML;
}
}
}
var xml = (new DOMParser()).parseFromString(text, "text/xml");
[/code]

where "text" (in the last line) is a string with the response I recieve from the server. In firefox and opera it works fine, but in Iexplorer "xml"(in the last line) is a empty xml document no matter what I do input as "text". What am I doing wrong?

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories