L
laramie.hartmann
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. Any
suggestions are greatly appreciated as I've been stuck on this for a
while now.
Thanks,
Laramie Hartmann
Here is a sample record from my XML file...
<?xml version="1.0" ?>
<DOCTOR>
<PHOTO>facholonu.jpg</PHOTO>
<NAME>Felix N. Acholonu, M.D.</NAME>
<SNAME>FACH</SNAME>
<OFFICE>
<ADDRESS>
<STREET>1801 Barrs St., Ste. 920</STREET>
<CITY>Jacksonville</CITY>
<STATE>FL</STATE>
<ZIP>32204</ZIP>
<PHONE>(904) 387-1401</PHONE>
</ADDRESS>
<ABBR>STV5</ABBR>
<FULL>St. Vincent's 5</FULL>
</OFFICE>
<SPECIALTY>Obstetrics & Gynecology</SPECIALTY>
<HOSPITAL>St. vincent's Medical Center</HOSPITAL>
<COLLEGE>SUNY Health Science Center</COLLEGE>
<GRADUATION>1981</GRADUATION>
<BOARD>American Board of Obstetrics & Gynecology</BOARD>
<BLURB></BLURB>
</DOCTOR>
Here is the javascript...
<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");
var x=xmlDoc.getElementsByTagName("PHOTO")
var nm=xmlDoc.getElementsByTagName("NAME")
var sname=xmlDoc.getElementsByTagName("SNAME")
var abbr=xmlDoc.getElementsByTagName("ABBR")
var full=xmlDoc.getElementsByTagName("FULL")
var street=xmlDoc.getElementsByTagName("STREET")
var city=xmlDoc.getElementsByTagName("CITY")
var state=xmlDoc.getElementsByTagName("STATE")
var zip=xmlDoc.getElementsByTagName("ZIP")
var phone=xmlDoc.getElementsByTagName("PHONE")
var specialty=xmlDoc.getElementsByTagName("SPECIALTY")
var tem = window.location.search;
tem = tem.substring(10,14);
for (var i = 1; i <= x.length; i++)
{
if (tem == abbr.item(i-1).text || tem == "" || tem == "ALLD")
{
document.write("<div class='square'>")
document.write("<img class='bimg' src='" + x.item(i-1).text + "'
width='125' height='150'></img>")
document.write("<div class='nameblock'>")
document.write("<strong><a href='bio.html?caregiver=" +
sname.item(i-1).text + "'>" + nm.item(i-1).text + "</a></strong><br
/>")
document.write("<a href='division.html?division=" +
abbr.item(i-1).text + "'>" + full.item(i-1).text + "</a><br />")
document.write(street.item(i-1).text + "<br />")
document.write(city.item(i-1).text + ", " + state.item(i-1).text + " "
+ zip.item(i-1).text)
document.write("</div>")
document.write("<div class='clearer'></div>")
document.write("</div>")
}
}
var division = document.getElementById("division")
for (i = 0; i < division.length; i++)
{
if (tem == division.options.value)
{
division.options.selected = true
}
}
var name=xmlDoc.getElementsByTagName("NAME")
var docs = document.getElementById("caregiver")
var len = docs.length
for (var i = 0; i < sname.length; i++)
{
docs.options[len+i] = new Option(name.item(i).text)
docs.options[len+i].value = sname.item(i).text
}
//]]>
</script>
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. Any
suggestions are greatly appreciated as I've been stuck on this for a
while now.
Thanks,
Laramie Hartmann
Here is a sample record from my XML file...
<?xml version="1.0" ?>
<DOCTOR>
<PHOTO>facholonu.jpg</PHOTO>
<NAME>Felix N. Acholonu, M.D.</NAME>
<SNAME>FACH</SNAME>
<OFFICE>
<ADDRESS>
<STREET>1801 Barrs St., Ste. 920</STREET>
<CITY>Jacksonville</CITY>
<STATE>FL</STATE>
<ZIP>32204</ZIP>
<PHONE>(904) 387-1401</PHONE>
</ADDRESS>
<ABBR>STV5</ABBR>
<FULL>St. Vincent's 5</FULL>
</OFFICE>
<SPECIALTY>Obstetrics & Gynecology</SPECIALTY>
<HOSPITAL>St. vincent's Medical Center</HOSPITAL>
<COLLEGE>SUNY Health Science Center</COLLEGE>
<GRADUATION>1981</GRADUATION>
<BOARD>American Board of Obstetrics & Gynecology</BOARD>
<BLURB></BLURB>
</DOCTOR>
Here is the javascript...
<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");
var x=xmlDoc.getElementsByTagName("PHOTO")
var nm=xmlDoc.getElementsByTagName("NAME")
var sname=xmlDoc.getElementsByTagName("SNAME")
var abbr=xmlDoc.getElementsByTagName("ABBR")
var full=xmlDoc.getElementsByTagName("FULL")
var street=xmlDoc.getElementsByTagName("STREET")
var city=xmlDoc.getElementsByTagName("CITY")
var state=xmlDoc.getElementsByTagName("STATE")
var zip=xmlDoc.getElementsByTagName("ZIP")
var phone=xmlDoc.getElementsByTagName("PHONE")
var specialty=xmlDoc.getElementsByTagName("SPECIALTY")
var tem = window.location.search;
tem = tem.substring(10,14);
for (var i = 1; i <= x.length; i++)
{
if (tem == abbr.item(i-1).text || tem == "" || tem == "ALLD")
{
document.write("<div class='square'>")
document.write("<img class='bimg' src='" + x.item(i-1).text + "'
width='125' height='150'></img>")
document.write("<div class='nameblock'>")
document.write("<strong><a href='bio.html?caregiver=" +
sname.item(i-1).text + "'>" + nm.item(i-1).text + "</a></strong><br
/>")
document.write("<a href='division.html?division=" +
abbr.item(i-1).text + "'>" + full.item(i-1).text + "</a><br />")
document.write(street.item(i-1).text + "<br />")
document.write(city.item(i-1).text + ", " + state.item(i-1).text + " "
+ zip.item(i-1).text)
document.write("</div>")
document.write("<div class='clearer'></div>")
document.write("</div>")
}
}
var division = document.getElementById("division")
for (i = 0; i < division.length; i++)
{
if (tem == division.options.value)
{
division.options.selected = true
}
}
var name=xmlDoc.getElementsByTagName("NAME")
var docs = document.getElementById("caregiver")
var len = docs.length
for (var i = 0; i < sname.length; i++)
{
docs.options[len+i] = new Option(name.item(i).text)
docs.options[len+i].value = sname.item(i).text
}
//]]>
</script>