Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > XML DOM problem in Firefox

Thread Tools

XML DOM problem in Firefox
Posts: n/a
Hi everyone.

I just made a JavaScript program to read a RSS feeds and display it in
a HTML file. The script - Jasfer or JAvaScript FEed Reader - is
available at

The problem that I have is that this script works only in IE. The XML
reading part goes fine - but I don't know how to access the DOM
sturcture in Firefox. The used code is given below.

/////////////////////////////////////// XML File Loading
function xmlProcessor(data) {
nodes = data.documentElement.childNodes.item(0).childNodes
alert("Length : " + nodes.length
+ "\nFirst Item : " + nodes.item(0).nodeName
+ "\nFirst Item Value : " + nodes.item(0).childNodes[0].text);

//Firefox only function - happens when a XML file is loaded
function loadHandler () {
xmlProcessor(this); //Call the Commen function with 'this' data.

//Load the xml file - using different method for different browsers
function xmlLoad(xml_file) {
feed_id = 0;
feed_total = 0;

var xmlDocument = "";
feed_file = xml_file;
if(document.implementation.createDocument) {//Firefox
xmlDocument = document.implementation.createDocument('', '', null);
xmlDocument.addEventListener('load', loadHandler, false); //This
function will happen when the file is loaded
else { //IE
var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
xmlDocument.async = false;
var loadResult = xmlDocument.load(xml_file);
if (loadResult) {
// process xml document with DOM methods e.g.
} else {
return false;
return true;



The script works well in both bowers(IE and Firefox) till the
xmlProcessor() function is reached. I don't know how to use XML DOM
structure in Firefox. If any one knows the location of a good
tutorial/manual about this feature, please let me know.

Any help to get this script working in Firefox(and other browers) is
greatly appreciated.

Binny V A

Reply With Quote
Martin Honnen
Posts: n/a
      08-03-2005 Removed) wrote:

> function xmlProcessor(data) {
> nodes = data.documentElement.childNodes.item(0).childNodes

Trying to work with the childNodes collection in the hope that you find
a certain node at a certain index is indeed dangerous in cross browser
scripting. The problem is that Mozilla always includes text nodes with
white space in the DOM while MSXML used by IE for XML does not do that
by default. So your attempt to use
could end up being an element node with MSXML/IE but a text node with
There are however other ways to access nodes, if you are looking for
certain elements then there is
Or use childNodes but make sure that you check the nodeType of a node to
be 1 if you are looking for element nodes.


Martin Honnen
Reply With Quote
Paul Gorodyansky
Posts: n/a

Paul Gorodyansky wrote:
> Martin, could you please look at another Mozilla/Firefox issue
> related to your article in
> The approach offered in the article has a serious problem described
> in this Newsgroup 2 days ago (I hope there is a solution):

Here is the link to the thread:

Reply With Quote

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
getNextSibling() never ends? DOM XML nodes (org.w3c.dom) Alan Java 6 10-13-2008 05:48 PM
How IE's and Firefox's XML DOM parsers deal with whitespace text nodes Water Cooler v2 XML 1 11-02-2007 03:38 PM
How IE's and Firefox's XML DOM parsers deal with whitespace text nodes Water Cooler v2 XML 0 11-02-2007 02:28 PM
Replacing _xmlplus.dom.minidom with xml.dom.minidom Python 3 08-03-2007 03:50 PM
Convert a XML DOM Object to a HTML DOM Object XML 0 09-20-2005 08:16 AM