[thelist] Loading XML file in IE browser

Roger Ly evolt at matchpenalty.com
Wed Jun 18 11:35:33 CDT 2003


Hey all,
 
I'm having a really tough time trying to debug a situation where I am
loading an external XML doc using the technique described at ppk's site
(http://www.xs4all.nl/~ppk/js/importxml.html).
 
In a nutshell, I have an HTML document which tries to load an external
XML doc, and use the values in that document to help populate the DOM.
 
I stripped down version of the page I am using is at
http://rogerly.f2o.org/blah.html (xml is at
http://rogerly.f2o.org/album.xml).  
 
The area I am having trouble with is in this set of functions:
 
            function importXML(albumName)
            {
                        if (document.implementation &&
document.implementation.createDocument)
                        {
                                    xmlDoc =
document.implementation.createDocument("", "", null);
                                    xmlDoc.onload = loadAlbum;
                        }
                        else if (window.ActiveXObject)
                        {
                                    xmlDoc = new
ActiveXObject("Microsoft.XMLDOM");
                                    xmlDoc.onreadystatechange = function
() {
                                                if (xmlDoc.readyState ==
4) loadAlbum()
                                    };
                        }
                        else
                        {
                                    alert('Your browser can\'t handle
this script');
                                    return;
                        }
                        xmlDoc.load("album.xml");
            }
 
            function loadAlbum()
            {
                        var album =
xmlDoc.getElementsByTagName('Album');
                        if (album.length == 0)
                        {
                                    alert('it doesnt look like the xml
was loaded properly');
                        }
                        var albumChildren = album[0].childNodes;
                        for (var i = 0; i < albumChildren.length; i++)
                        {
                                    handleAlbumChild(albumChildren[i]);
                        }
            }
 
In the loadAlbum() function, where I do the check to see if album.length
== 0, there are times where the Album node thinks that it doesn't have
any children.  What's weird is that usually, when I load the XML the
first time, everything works fine, but other times it doesn't work at
all.  When it fails, the top-level node read in from the Album.xml is
fine, but none of its children are loaded, which breaks everything for
me.
 
Does anyone have any good insight in how the Microsoft.XMLDOM ActiveX
object works?  Has anyone heard of any situations where trying to load
an XML document using that object has failed for some unknown reason?
Unfortunately, I can't think of any other ways to debug the stuff except
to throw in alerts here or there in the Javascript.
 
Thanks,
 
Roger
 
 


More information about the thelist mailing list