Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 11th, 2008, 06:15 AM
avpkills2002@gmail.com
Guest
 
Posts: n/a
Default XML Parsing Problem in Internet Explorer

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
  #2  
Old October 11th, 2008, 01:05 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: XML Parsing Problem in Internet Explorer

avpkills2002@gmail.com wrote:
Quote:
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?
Quote:
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);
}


Quote:
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/
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles