user2669989
user2669989

Reputation: 270

XML parser for other browsers except IE

How to write below piece of code so that it works on all browser. Currently it is workng in IE only.

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(respText);

var element1 = xmlDoc.getElementsByTagName("element1");
var element2 = xmlDoc.getElementsByTagName("element2");

Appreciate any guidance in resolving this?

Thanks, Jdp

Upvotes: 0

Views: 35

Answers (1)

David Mulder
David Mulder

Reputation: 27010

If you would jQuery I would first just retrieve the data through a normal GET request and then use jQuery.parseXML() to parse it. This takes care of all the different cross platform issues and additionally gives you some excellent tools to handle the xml structure more easily.

Of course there are other libraries as well who do similar things, but I would not advice you to do this from scratch yourself as there are quite a number of browser differences I can tell you from experience (I mean, you could just use XMLHttpRequest and DOMParser and you will get quite far, but there are some frustrating differences between older browser implementations).

And one last thing, never ever disable async loading of resources. Why risk irritating the user with freezing his browser if JS is build to make async processing easy in regards to some functions at least such as loading external resources.

Upvotes: 1

Related Questions