Matthew Coertze

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromMatthew Coertze
ToMe
SubjectimportXML ie6 iframe problem
Date23 November 2005 19:42
Hello Tarquin, first up, thanx for your importXML script, you've saved me
ages in tracking the various issues down. (Your other scripts look great
too, but I haven't had a chance to download/study them yet).

Anyhow, on to the reason for my e-mail - importXML.js, problems and possible
solutions:

1) IE6 on Xp sp2 returns gibberish when it downgrades to the iframe
solution - probably in much the same way Konquerer does - I refer to your
code at the start of createTable below, which traps the IE6 error as well:
[code]
/* Konqueror insists that the timer can keep running until there are 20
alerts (the file is still in the list of files to be checked until at least
one alert is dismissed), so I use a timer to delay the alert and allow my
script to stop checking the file */
if( xmlDoc.documentElement && xmlDoc.documentElement.tagName &&
xmlDoc.documentElement.tagName.toUpperCase() == 'HTML' ) {
setTimeout('alert(\'For no apparent reason, your browser has turned the
clean XML into HTML based garbage.\\nScript aborted.\');',50); return; }
[/code]

The fix: Upon investigating, I discovered that the iframes section of
importXML should return
window.frames['iframename'].window.document.XMLDocument for IE6, instead of
just window.frames['iframename'].window.document
Now I know this makes no sense. MSDN itself says the XMLDocument part is
optional, but there you have it. It works for IE6. Unfortunately, however,
it breaks the iframe solution for Firefox 1.5 and Netscape 8 (Opera 8.5 is
still happy). Since I don't have Konqueror, I don't know if the same fix
will work for that too.

Implementing the fix: Probably the fix should go into MWJ_checkXMLLoad,
something like

if(window.frames['MWJ_XML_loader_'+x].window.document.documentElement) {
setTimeout( MWJ_ldD[x].split('MWJ_SPLIT')[0] +
'(window.frames.MWJ_XML_loader_'+x+'.window.document.XMLDocument);',
parseInt(MWJ_ldD[x].split('MWJ_SPLIT')[1]) );
} else {
setTimeout( MWJ_ldD[x].split('MWJ_SPLIT')[0] +
'(window.frames.MWJ_XML_loader_'+x+'.window.document);',
parseInt(MWJ_ldD[x].split('MWJ_SPLIT')[1]) );
}

Your thoughts on this would be appreciated.

2) In checking the e-mails for a solution to 1) above, I saw a post about
importXML not catering properly for IE with activeX disabled. To cater for
this this I changed the code from:

[oldcode]
if( !navigator.__ice_version && window.ActiveXObject ) {

the Microsoft way - IE 5+/Win (ICE produces errors and fails to use
try-catch correctly)

try { //IE Mac has the property window.ActiveXObject but produces errors if
you try and use it

try { var tho = new ActiveXObject( 'Microsoft.XMLDOM' ); //newer

} catch(e) { var tho = new ActiveXObject( 'Msxml2.XMLHTTP' ); } //older

MWJ_ldD[MWJ_ldD.length] = tho;

MWJ_ldD[MWJ_ldD.length-1].onreadystatechange = new Function( 'if(
MWJ_ldD['+(MWJ_ldD.length-1)+'].readyState == 4 ) {
'+oFunct+'(MWJ_ldD['+(MWJ_ldD.length-1)+']); }' );

MWJ_ldD[MWJ_ldD.length-1].load(oURL);

return true;

} catch(e) {}

}

[/oldcode]

to...

[code]

if( !navigator.__ice_version && window.ActiveXObject ) {

//activeX XMLDOM/HTTP request - IE Win, Ice etc

var tho=MWJ_ActiveXDOM( 'Microsoft.XMLDOM' ); //newer

if(!tho) tho=MWJ_ActiveXDOM( 'Msxml2.XMLHTTP' ); // older

if(tho) return true;

}

[/code]

and created a new function as below:

[code]

function MWJ_ActiveXDOM(dom) {

var tho;

try {

tho = new ActiveXObject( dom );

MWJ_ldD[index] = tho;

MWJ_ldD[index].onreadystatechange = new Function( 'if(
MWJ_ldD['+index+'].readyState == 4 ) {
'+oFunct+'(MWJ_ldD['+index+'],'+index+'); }' );

MWJ_ldD[index].load(oURL);

} catch(e) { }

return tho;

}

[/code]

Which fails gracefully in IE6 with activeX disabled, and should catch the IE
mac problem too. (Although I can't test that).

Again, your thoughts would be appreciated.

3) The last point about importXML.js is that, as I'm sure you know, it is
not reentrant and can cause a memory leak. For example, say I have a xml
file called news.xml which I refresh on the server periodically, and hence
want to reload from my page every few minutes. Every call to importXML will
allocate a new array entry and hence use more memory. To get around this I
changed importXML to receive an index as input, and also now pass the
allocated index as part of the function callback. If you would like me to
post the changes I will gladly do so.

Your thoughts on this too appreciated.

Thanking you for a wonderful script

Jacob Matthew Coertze
FromMe
ToMatthew Coertze
SubjectRe: importXML ie6 iframe problem
Date23 November 2005 20:04
Matthew,

> 1) IE6 on Xp sp2 returns gibberish when it downgrades to the iframe
> solution

IE 6 does not understand the iframe, but it also should not need to. It can
do proper importing XML. Note, however, that it needs ActiveX to be enabled.
This will be fixed in IE 7 (when it is finally released). I do not intend to
amend the script to cope with this situation. IE 6 is a bad browser, and
this reliance on ActiveX is simply annoying, and unnecessary. Microsoft
recognise this, which is why they will be fixing it in IE 7. I will let them
fix their problem, instead of trying to work around it. In normal installs,
it will work (and of course, it will always work in the better browsers,
without needing ActiveX).

If ActiveX is enabled, and it still fails, then we have a problem, because
it should not be going down the iframe branch. Is this the case?

> The last point about importXML.js is that, as I'm sure you know, it is
> not reentrant and can cause a memory leak. For example, say I have a xml
> file called news.xml which I refresh on the server periodically, and hence
> want to reload from my page every few minutes. Every call to importXML will
> allocate a new array entry and hence use more memory. 

The behaviour is intentional, since I originally wrote it to be for proper
asynchronous functionality. With a re-use system, you risk overwriting
something you are still using, and may wish to retain for use later. In the
scripts I was using it for, I wanted this behaviour.

> To get around this I
> changed importXML to receive an index as input, and also now pass the
> allocated index as part of the function callback. If you would like me to
> post the changes I will gladly do so.

This is a nice idea, since you can selectively overwrite what you do not
need (assuming this does not become too complex for your own scripts to
manage). A good way of dealing with the situation. I may add this
functionality in a future release.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromMatthew Coertze
ToMe
SubjectRe: importXML ie6 iframe problem
Date24 November 2005 06:59
Tarquin, thanx for the quick response.

> If ActiveX is enabled, and it still fails, then we have a problem,
> because it should not be going down the iframe branch. Is this the case?

No. I wanted to cater for the case where the user has consciously disabled activeX,
and thus I would need to use the iframe solution. The fix I posted works fine for
catching the activeX disable, and the 'if' for using XMLDocument or not (as posted) also works.
So basically, I'm all set :) I just wanted to give you the feedback and in case others also
needed the workarounds.

Thanx again

Matthew
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.