Connecting Tech Pros Worldwide Help | Site Map

XML DOM problem in Firefox

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 3rd, 2005, 06:45 PM
binnyva@gmail.com
Guest
 
Posts: n/a
Default XML DOM problem in Firefox

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 http://www.geocities.com/binnyva/cod...script/jasfer/

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) {
//Initializations
feed_id = 0;
feed_total = 0;

var xmlDocument = "";
feed_file = xml_file;
if(document.implementation.createDocument) {//Firefox
xmlDocument = document.implementation.createDocument('', '', null);
xmlDocument.load(xml_file);
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.
xmlProcessor(xmlDocument)
} else {
feedError();
return false;
}
}
return true;
}

xmlLoad("hhtp://www.geocities.com/binnyva/code/rss.xml");

/////////////////////////////////

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.

Thanks.
Binny V A
http://binnyva.blogspot.com/


  #2  
Old August 3rd, 2005, 06:55 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: XML DOM problem in Firefox



binnyva@gmail.com wrote:

[color=blue]
> function xmlProcessor(data) {
> nodes = data.documentElement.childNodes.item(0).childNodes[/color]

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
data.documentElement.childNodes.item(0)
could end up being an element node with MSXML/IE but a text node with
Mozilla.
There are however other ways to access nodes, if you are looking for
certain elements then there is
data.getElementsByTagName('tagname').item(0)
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
http://JavaScript.FAQTs.com/
  #3  
Old August 4th, 2005, 01:55 AM
Paul Gorodyansky
Guest
 
Posts: n/a
Default Re: XML DOM problem in Firefox

Hi,

Martin, could you please look at another Mozilla/Firefox issue
related to your article in http://JavaScript.FAQTs.com/?
The approach offered in the article has a serious problem described
in this Newsgroup 2 days ago (I hope there is a solution):

http://groups.google.com/group/comp....fb016f9?hl=en&

--
Regards,
Paul
  #4  
Old August 5th, 2005, 12:45 AM
Paul Gorodyansky
Guest
 
Posts: n/a
Default Re: XML DOM problem in Firefox

Hi,

Paul Gorodyansky wrote:[color=blue]
>
>
> Martin, could you please look at another Mozilla/Firefox issue
> related to your article in http://JavaScript.FAQTs.com/?
> The approach offered in the article has a serious problem described
> in this Newsgroup 2 days ago (I hope there is a solution):
>
> http://groups.google.com/group/comp....fb016f9?hl=en&[/color]

Here is the link to the thread:
http://groups.google.com/group/comp....14e34bffb016f9


--
Regards,
Paul
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Popular Articles

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 220,662 network members.