By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,848 Members | 3,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,848 IT Pros & Developers. It's quick & easy.

XML Parsing Problem in Internet Explorer

P: n/a
I seem to be getting this weird problem in Internet explorer. I have
written a code for parsing a XML file and displaying the output. The
code works perfectly fine with ffx(Firefox).However is not working in
Internet Explorer.(I m using Internet Explorer 6.0). The code is as
follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="dojo-release-1.1.1/dojo/dojo.js"
djConfig="parseOnLoad:true">
</script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.TitlePane");
</script>
<style type="text/css">
@import "dojo-release-1.1.1/dojo/resources/dojo.css";
@import "dojo-release-1.1.1/dijit/themes/tundra/tundra.css";
#output
{
width:500px;
}
</style>
<script language="javascript">
function create_button(titletoapply,idtoapply,cont)
{
ttltoapply = titletoapply;
ids = idtoapply;
conti = cont;
elementcreator(ids,conti);
var params = {

// Note here, when creating programmatically,
this is a function, not a string
open:false,
title:ttltoapply
};

var button_dynamic = new dijit.TitlePane(
params,dojo.byId(ids)
);
}
function elementcreator(id,content)
{
var idtoassign = id;
var contenttoassign = content;
var browser = navigator.userAgent;
if(browser.indexOf("MSIE") != -1)
{
var diselement = document.createElement('div');
var diselementattrib = document.createAttribute('id');
diselementattrib.value = idtoassign;
diselement.setAttributeNode(diselementattrib);
diselement.innerHTML = contenttoassign;

var core = document.getElementById('output');
core.appendChild(diselement);
}
else
{
var elem = document.createElement('div');
elem.setAttribute('id',idtoassign);
elem.innerHTML = contenttoassign;
var core = document.getElementById('output');
core.appendChild(elem);
}
}
function createXHR()
{
try{return new XMLHttpRequest();}catch(e){}
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
}
function sendrequest()
{
var xhr = createXHR();
xhr.open("GET","Example1.xml",true);
xhr.onreadystatechange = function(){handleresponse(xhr);}
xhr.send(null);
}
function handleresponse(xhr)
{
var response = xhr.responseXML;
var rssentries=response.getElementsByTagName("item");
var linku;
var title;
var idgenerated;
for (var i=0; i<rssentries.length; i++){
idgenerated = "count" + i;
linku=rssentries[i].getElementsByTagName('link')
[0].firstChild.nodeValue;
title=rssentries[i].getElementsByTagName('title')
[0].firstChild.nodeValue;
//create_button(title,idgenerated,linku);
elementcreator(idgenerated,title);
}

var display = document.getElementById('output');
//display.innerHTML = output;
}
function closetabs()
{
var core=document.getElementById("bbdy");
var child=document.getElementById("output");
core.removeChild(child);
}
</script>
</head>

<body class="tundra" id="bbdy">
<div id="output"></div>
<button onclick="sendrequest()">Process</button>
<button onclick="closetabs()">remove</button>
</body>
</html>

P.S: The dojo part of the script can be commented as it has no
relation with the working of logic

The xml file for this is as follows

<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="0.91">
<channel>
<title>JavaScriptKit.com</title>
<link>http://www.javascriptkit.com</link>
<description>JavaScript tutorials and over 400+ free scripts!</
description>
<language>en</language>

<item>
<title>Document Text Resizer</title>
<link>http://www.javascriptkit.com/script/script2/
doctextresizer.shtml</link>
<description>This script adds the ability for your users to toggle
your webpage's font size, with persistent cookies then used to
remember the setting</description>
</item>

<item>
<title>JavaScript Reference- Keyboard/ Mouse Buttons Events</title>
<link>http://www.javascriptkit.com/jsref/eventkeyboardmouse.shtml</
link>
<description>The latest update to our JS Reference takes a hard look
at keyboard and mouse button events in JavaScript, including the
unicode value of each key.</description>
</item>

<item>
<title>Dynamically loading an external JavaScript or CSS file</title>
<link>http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml</
link>
<description>External JavaScript or CSS files do not always have to be
synchronously loaded as part of the page, but dynamically as well. In
this tutorial, see how.</description>
</item>

</channel>
</rss>

Please can anyone provide me solution for this prob
Oct 11 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
av**********@gmail.com wrote:
I seem to be getting this weird problem in Internet explorer. I have
written a code for parsing a XML file and displaying the output. The
code works perfectly fine with ffx(Firefox).However is not working in
Internet Explorer.(I m using Internet Explorer 6.0).
Do you get any error with IE? If so which one, for which line?
function elementcreator(id,content)
{
var idtoassign = id;
var contenttoassign = content;
var browser = navigator.userAgent;
if(browser.indexOf("MSIE") != -1)
{
var diselement = document.createElement('div');
var diselementattrib = document.createAttribute('id');
diselementattrib.value = idtoassign;
diselement.setAttributeNode(diselementattrib);
diselement.innerHTML = contenttoassign;

var core = document.getElementById('output');
core.appendChild(diselement);
}
else
{
var elem = document.createElement('div');
elem.setAttribute('id',idtoassign);
elem.innerHTML = contenttoassign;
var core = document.getElementById('output');
core.appendChild(elem);
}
}
That can be shortened to

function elementcreator(id,content)
{
var diselement = document.createElement('div');
diselement.id = id;

diselement.innerHTML = content;

var core = document.getElementById('output');
core.appendChild(diselement);
}
function sendrequest()
{
var xhr = createXHR();
xhr.open("GET","Example1.xml",true);
xhr.onreadystatechange = function(){handleresponse(xhr);}
I think you want
xhr.onreadystatechange = function()
{
if (xhr.readyState === 4)
{
handleresponse(xhr);
}
};


--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 11 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.