dean.edwards.name/weblog/2004/11/ie7-xml-extras/

IE7 XML Extras

The XMLHttpRequest object has been getting some renewed attention lately. This is due to it being implemented in two more browsers (Opera and Safari). It was originally introduced by Microsoft in IE5.0 using (despised) ActiveX technology. It first appeared as a native JavaScript object as part of Mozilla’s XML extras and is now on its way to becoming a standard.

A new IE7 module (ie7-xml-extras.js) provides an emulation of Mozilla’s XML objects:

This new module provides wrappers for the underlying ActiveX objects. This is a slightly heavy handed way to implement cross-browser support and more lightweight solutions have been around for a while. But if you are a purist, then you may want to download the code. Although the module is part of IE7 it will also work as a standalone module.

Comments (20)

Leave a comment

Great stuff! Unless you get there first, may drop by something with some of the other stuff Mozilla’s implementation has (e.g. onload / onerror / addEventListener() etc.).

xmlhttprequest info: XMLHttpRequest Introduction IE 7 xml-extras xmlhttprequest calendar

Excellent! Just the one platform to target, now for XMLHttp as well.

  • Comment by: Nelson Menezes
  • Posted:

What am I doing wrong here?

http://www.dougweb.org/xmlhttp/index.html

It works in Gecko, but not IE..

Doug, it seems that Microsoft’s responseXML property is not the same as Mozilla’s. I need to code around this. Expect an update soon.

  • Comment by: -dean
  • Posted:

Please note that you should wrap the script in conditional comments as described in the IE7 usage page.

  • Comment by: -dean
  • Posted:

Why not have also a DOM3 XPath implementation as mozilla do ?

See http://blogs.msdn.com/dareobasanjo/archive/2004/04/20/116815.aspx

  • Comment by: BJB
  • Posted:

Dean – was comment 6 directed at me, or a general warning to all? Because I am using the conditional comments.

Doug, it was a general comment. Seeing your test page reminded me to remind everyone else. :-)

  • Comment by: -dean
  • Posted:

I vote “yeay!” to the XPath extension! (now at https://sourceforge.net/projects/html-xpath/)

  • Comment by: Nelson Menezes
  • Posted:

Dimitri Glazkov (the author of the XPath extension) and I have already spoken about his project eventually becoming an IE7 module. The birth of his baby boy slowed down development a little as I recall. :-)

Maybe it’s time to contact Dimitri again…

  • Comment by: -dean
  • Posted:

Whoa. A blog and everything. I must’ve been really caught in the “newborn time warp” :)

I would be very interested in getting the html-xpath project integrated as an extension. Time, as was mentioned earlier, still comes at a premium, but I think I may have more of it now.

This blogging thing really works…

  • Comment by: -dean
  • Posted:

Dean, this is great! One small addition by me – even if it is faked up. I am working on something crossbrowser and found a script that attaches an onload handler to the request object. alike

var oR = new XMLHttpRequest();
oR.open(this.method, this.url, this.async);
oR.setRequestHeader(sCType,sMimeType);
oR.onload = function(){
...
}
oR.onerror = function(){
...
}

this point the script did continue in a mozilla firefox browser but stalled in IE 6. So I modified your solution to make it work – but as I said before I have no idea if I have done it the right way. :-)

function onreadystatechange() {
	// refresh properties
	update();
	// call the public event handler (if it is set)
	if (typeof _public.onreadystatechange == "function") {
		_public.onreadystatechange();
	}
	// trying to fake onload
	// readyState 4
	if ((_private.readystate == 4) && (typeof _public.onload == "function")) {
		_public.onload();
	}
};

But what to do about the onerror handler? regards ralf

Does anyone know of any documentation on how to use IE 7 xml Exrtas? I have been reading up but I’m having trouble finding a useful source.

  • Comment by: Tom Loudon
  • Posted:

Does anyone know of any documentation on how to use IE 7 xml Exrtas?

What problems are you having Tom? You should be able to use the XMLHttpRequest the same as you can in Mozilla:

http://www.mozilla.org/xmlextras/

Remember to include the script in conditional comments to hide it from non-IE browsers:

<!--[if lt IE 7]>
<script src="/ie7/ie7-xml-extras.js" type="text/javascript"></script>
<![endif]-->

There is lots of additional information here:

http://jpspan.sourceforge.net/wiki/doku.php?id=javascript:xmlhttprequest

  • Comment by: -dean
  • Posted:

Doug, you are using the wrong mime-type on the page you’re retrieving; it’s not xml. Change and it will work. Or use a different function with responseText instead (much better if you just want a snippet anyway).

Dean, doesn’t seem to be a problem with responseXML in your code as you think. Works fine for me but then so does one line assigning new xmlhttprequest to new activexobject for ie without all the extra code so I was wondering what all you were trying to fix in that module (not including the extras there).

  • Comment by: stylo~
  • Posted:

[...] I just noticed that Dean Edwards’ IE compatibility layer has been updated with a new xml objects module which can emulate Mozilla’s xmlhttprequest functionality. wordpr [...]

Dean, Any word on the .responseXML issues?

Great work, thanks

  • Comment by: michael
  • Posted:

Michael, version 0.9 of IE7 includes a simpler wrapper for the XMLHttpRequest object. Hopefully this will solve the problem you are experiencing.

  • Comment by: -dean
  • Posted:

Leave A Comment

Line and paragraph breaks automatic, email address never displayed. Some HTML allowed.