laramie.hartmann@gmail.com wrote:
Quote:
I have a script (see below) that accesses a XML file and displays the
contents through a series of document.write calls. This all works fine
in IE, but not at all in Firefox. I get no errors in the javascript
console, but when I try to load the elements by tag name and look at
the length it is always 0 as if no elements have been added.
<script type="text/javascript">
//<![CDATA[
if (window.ActiveXObject)
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false; //Enforce download of XML file first. IE only.
document.write("Internet Explorer");
}
else if (document.implementation &&
document.implementation.createDocument)
{
>
xmlDoc = document.implementation.createDocument("", "doc", null);
>
document.write("Firefox");
}
>
xmlDoc.load("caregivers.xml");
By default Mozilla loads the XML asynchronously so you need to add an
onload handler and process the XML there (e.g. call getElementsByTagName
in the onload handler). Or you need to use xmlDoc.async = false before
you call the load method.
In my view if you want to load XML cross browser then using
XMLHttpRequest/XMLHTTP is easier as it requires less code differences, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/6826/fid/616>
Opera 8 for instance supports XMLHttpRequest but no load method for XML
DOM documents.
So consider loading the XML asynchronously with XMLHttpRequest/XMLHTTP
and then reading out values from the XML with the DOM and adding
contents to the HTML document with the DOM.
--
Martin Honnen
http://JavaScript.FAQTs.com/