473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Mozilla not displaying http_request data correctly, but IE is

I'm sure it's not mozilla's fault but I'm at a loss here.
I'm loading the following XML data into a page using
http_request:

<?xml version="1.0" encoding="iso-8859-1"?>
<forum>
<message id="msg1">
<date>10/13/2005</date>
<time>10:39 pm</time>
<name>Josh</name>
<comment>This is a message.</comment>
</message>
<message id="msg2">
<date>10/14/2005</date>
<time>11:00 pm</time>
<name>Jeff</name>
<comment>This is another message.</comment>
</message>
<message id="msg3">
<date>10/21/2005</date>
<time>3:21 pm</time>
<name>Jeff</name>
<comment>This is yet another message.</comment>
</message>
</forum>
The following functions retrieve the data and displays it on
the page:

function getmessages() {
var xmldoc = http_request.responseXML;
var
numberofmessages=xmldoc.getElementsByTagName('mess age').length
;
var root_node = xmldoc.getElementsByTagName('message');
for( var x = 0; x < numberofmessages; x++ ) {
var message =
root_node[x].childNodes[3].firstChild.nodeValue;
insertcontent(message);
var messagedatetime =
root_node[x].childNodes[2].firstChild.nodeValue + " [" +
root_node[x].childNodes[0].nodeName + ": " +
root_node[x].childNodes[0].firstChild.nodeValue + " -- " +
root_node[x].childNodes[1].nodeName + ": " +
root_node[x].childNodes[1].firstChild.nodeValue + "]" ;
insertcontent(messagedatetime);
}
insertcontent(numberofmessages);
}

function insertcontent(words) {
var ourDiv=document.getElementById('chatbox');
var ptag=document.createElement('p'); // create p tag
var chattext=document.createTextNode(words);// - create
the text to go in p tag
ptag.appendChild(chattext); // put text in p tag
ourDiv.appendChild(ptag); //put p tag in div
}

IE displays the results correctly:

This is a message.

Josh [date: 10/13/2005 -- time: 10:39 pm]

This is another message.

Jeff [date: 10/14/2005 -- time: 11:00 pm]

This is yet another message.

Jeff [date: 10/21/2005 -- time: 3:21 pm]

3
But Mozilla only shows:

10:39 pm

Any clues?????
Oct 26 '05 #1
2 1677


partridge wrote:
I'm sure it's not mozilla's fault but I'm at a loss here.
I'm loading the following XML data into a page using
http_request:

<?xml version="1.0" encoding="iso-8859-1"?>
<forum>
<message id="msg1">
<date>10/13/2005</date>
<time>10:39 pm</time>
<name>Josh</name>
<comment>This is a message.</comment>
</message>


Mozilla (and Opera too) by default includes white space between elements
as text nodes in the DOM while MSXML used by IE by default does not.
So any script trying to access an element as a child node at a certain
position (e.g. messageElement.childNodes[index]) will end up with
different nodes in the different implementations if the source XML is
formatted to have white space between elements, where MSXML/IE has an
element node Mozilla might have a text node.
Usually all you want is e.g.
messageElement.getElementsByTagName('date')[0]
that works whatever an implementation does with white space text.
But care needs to be taken if elements are nested recursively as
getElementsByTagName finds you all descendants while childNodes only the
descendants.
If you want to loop through childNodes then check
childNodes[index].nodeType to make sure you have an element.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 26 '05 #2
>

partridge wrote:
I'm sure it's not mozilla's fault but I'm at a loss
here. I'm loading the following XML data into a page
using http_request:

<?xml version="1.0" encoding="iso-8859-1"?>
<forum>
<message id="msg1">
<date>10/13/2005</date>
<time>10:39 pm</time>
<name>Josh</name>
<comment>This is a message.</comment>
</message>


Mozilla (and Opera too) by default includes white space
between elements as text nodes in the DOM while MSXML
used by IE by default does not. So any script trying to
access an element as a child node at a certain position
(e.g. messageElement.childNodes[index]) will end up with
different nodes in the different implementations if the
source XML is formatted to have white space between
elements, where MSXML/IE has an element node Mozilla
might have a text node. Usually all you want is e.g.
messageElement.getElementsByTagName('date')[0]
that works whatever an implementation does with white
space text. But care needs to be taken if elements are
nested recursively as getElementsByTagName finds you all
descendants while childNodes only the descendants.
If you want to loop through childNodes then check
childNodes[index].nodeType to make sure you have an
element.
--

Martin Honnen
http://JavaScript.FAQTs.com/


Excellent! Thank you. I totally forgotten about the white
space issue.
Oct 26 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dennis Hueckelheim | last post by:
Hallo everybody, I have a problem with a little socket script. ----- snipp ----- $out_clients = socket_accept($socket_out); $http_welcome = "HTTP/1.0 200 OK\r\nContent-type:...
1
by: doug | last post by:
With http_request, is there a debug mode or a way to see exactly what http_request is sending?
9
by: Randall Sell | last post by:
Can anyone confirm if I am being an idiot, or is this a bug in the CSS implementation of Netscape 7.x/Mozilla 1.4 ... give the following single HTML: <html> <head> <style type="text/css">...
3
by: Pete Gray | last post by:
I have this in my style sheet: ..intro { font-size:1.2em; font-family:"Comic Sans MS", cursive; letter-spacing:0.1em; } p.intro:first-letter {
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
1
by: James Pittman | last post by:
Hi, We have a web application (Docushare) that is protected by Siteminder SSO. I'd like to do an HTTP_Request on it. How do I have my script "log in" through Siteminder so that it can do its...
1
by: nick | last post by:
Is it possible to do the following? (note this is more of a curiosity thing than problem solving :)) var parameters = 'b=3&d=4'; http_request = new ActiveXObject("Msxml2.XMLHTTP");...
3
by: rjones326 | last post by:
Hi, I'm stupendously mystified by this strange activity. I cannot for the life of me figure out why this will not work in mozilla. I've spent hours mucking around with it. The php file is...
1
by: hamidawais | last post by:
Hi All I have a simple Ajax example that populates a combo box from the DB . The example is working fine on Internet explorer but it gives no result on Mozilla FireFox Given below is the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.