473,395 Members | 2,783 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,395 software developers and data experts.

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/

Aug 3 '05 #1
3 25401


bi*****@gmail.com 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
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/
Aug 3 '05 #2
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
Aug 4 '05 #3
Hi,

Paul Gorodyansky wrote:


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&


Here is the link to the thread:
http://groups.google.com/group/comp....14e34bffb016f9
--
Regards,
Paul
Aug 5 '05 #4

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

Similar topics

3
by: Jeremy Epstein | last post by:
I've got a 4-page form that lets users enter a whole lot of information, which is then submitted and emailed at the end. All the fields are stored as session data. The whole thing works fine: ...
6
by: Geoff | last post by:
When trying to focus a field in Firefox, I get the following error: Error: " nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame ::...
87
by: expertware | last post by:
Dear friends, My name is Pamela, I know little about CSS, but I would like to ask a question I have an image on a web page within a css layer: <DIV ID=MyLayer STYLE = "position:...
14
by: expertware | last post by:
Ok! to avoid confusion I will start a new argument. Thanks!! FIREFOX 1.0.7 AND IE6 viewed through DATATIME: a summary REPORT ===============================================================...
5
by: SPE - Stani's Python Editor | last post by:
Hi, During optimizing SPE for Ubuntu, I found something strange. I have Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not working: >>> import webbrowser >>>...
7
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script...
12
by: amit | last post by:
Hello group, I'm kinda skeptical about a code is being used in my js program. All it does is checking what browser is being run and finds out if FLASH is installed or not. This code works...
6
by: scotty | last post by:
I have a script that loops through an existing table list and prepares each href element node to trigger a function when an image is clicked. The function that will be run passes a property value...
7
by: Carlos Mendonça | last post by:
Has anyone managed to get ClickOnce to work with Firefox? It seems to me that it still has the same issues VS 2K5 had. I appreciate any comments or tips.
3
by: SAL | last post by:
Hello, I did google this issue and found some stuff related to BrowserCaps section of either web.config or machine.config but it didn't work. It seems that most pages in my webapp are okay but a...
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.