View Full Version : DOM Parser works fine in fire fox not IE

08-17-2006, 05:52 PM
i am just writing a simple javasript to rotat the text in a div and this works fine in firefox but not ie i get an items.lenght is null or not an object. here is the page

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Documen1</title>

<script type="text/javascript" >
var xmlstring = '\
<rss version="2.0">\
<title>Dr Casalino\'s Testimonial</title>\
<description>"I have been recommending and personally using \
DANIEL CHAPTER ONE products for nearly 10 years. \
These products are of high quality and effectiveness,\
and the DANIEL CHAPTER ONE staff is always helpful\
and knowledgeable."\
<title>Cancer - Brain Tumor</title>\
<description>"I had contracted leukemia and had three inoperable tumors. \
When I decided not to do chemotherapy or radiation, my father sent me \
BioMixx and 7 Herb Formula. Each day as I took it and got it into my \
system more and more, the better I felt. Then I added Garlic, Siberian \
Ginseng, and Bio*Shark."\
<title>Arthritis Story</title>\
<description>"I have rheumatoid arthritis...I felt terrible on the drugs I \
was given by the doctors. I could hardly walk; I couldn\t get in or out of \
the tub. Now I\m feeling a lot better; I\m practically cured! I just have \
twinges now and then, but I\m getting better all the time. BioMixx gave me \
energy and helped with the pain. Now I take GS1500, GDU, Micro Cal Plus, \
Bio*Shark, and Essential Cell Food as a multivitamin. I\m doing really well. \
I\d recommend this to anyone."\
<title>Acid Reflux</title>\
<description>Every time I ate, the food felt stuck. Even with water, the food \
didn\t want to go down. I felt like I was choking. At night I couldn\'t sleep \
due to heartburn. I went to the doctor so I could sleep. He said there was no \
cure, nothing I could do but take medication, or have an operation where they \
wrap the stomach around the esophagus. He said that works in 85% of cases. \
I didn\'t want to take the acid-blocking drug; I thought, if you block digestive \
acid, how can you then digest food?\
<description>Bernon had diabetes for 15 years. He would take Insulin 730-20 \
units in the morning, and R Insulin 2-4 times a day. R Insulin is a fast acting \
insulin to keep the person from going into shock. On Insulin, he felt sluggish. \
Bernon started on Daniel Chapter One products in June 2001. Endo24 - 3 scoops 3 \
times a day at first, now he takes 2 scoops twice a day, CP200 - 2 capsules a \
day; VAN 50 - 2 capsules 3 times day, and Bio C-1000 - 2 capsules twice a day.\
var xmlobject = new DOMParser().parseFromString(xmlstring, "text/xml");
var root = xmlobject.getElementsByTagName('rss')[0];
var tests = root.getElementsByTagName("channel");
var items = tests[0].getElementsByTagName("item");

var thisTest = 0;
function cycleTest()
if (++thisTest == items.length)
thisTest = 0;

var descriptions = items[thisTest].getElementsByTagName("description");
var titles = items[thisTest].getElementsByTagName("title");
var links = items[thisTest].getElementsByTagName("link");
title_val = titles[0].firstChild.nodeValue;
descriptions_val = descriptions[0].firstChild.nodeValue;
links_val = links[0].firstChild.nodeValue;
document.getElementById('test').innerHTML="<span class=\"prodnames_homepage\"><br>"+title_val+"</span><br>\
<span class=\"featuredprod_tekst\">"+descriptions_val+"</span><br>\
<span class=\"speciallink\"><a href=\""+links_val+"\">read entire testimonial &gt;&gt;</a></span>";

// change to next banner every 15 seconds
setTimeout("cycleTest()", 15000);
<!--<script type="text/javascript" src="test_rotate.js"></script>-->

<body bgcolor=ffffff onload="cycleTest()">

<div id="test">


Any Ideas why this doesnt work

08-17-2006, 09:15 PM
Try escaping the </ as <\/ so that the browser doesn't think it has reached the end of the script.

08-18-2006, 01:11 PM
Umm, I'm fairly sure IE doesn't support DOMParser().

08-30-2006, 07:06 PM
Umm, I'm fairly sure IE doesn't support DOMParser().
Exactly. There are alternatives you can use though. If you have a full document, you can use DOMDocument (http://msdn.microsoft.com/library/en-us/xmlsdk/html/832083b0-9400-48eb-aa3c-6447d4b55c91.asp) (with these object members (http://msdn.microsoft.com/library/en-us/xmlsdk/html/5996c682-3472-4b03-9fb0-1e08fcccdf35.asp))for instance.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum