473,323 Members | 1,537 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,323 software developers and data experts.

Problem Reading XML File with Firefox

The xml and javascript are below.
IE finds everything fine, Firefox gives the following error -
xmlDoc.getElementsByTagName("lab_name")[0] has no properties
on this line -
alert(xmlDoc.getElementsByTagName('lab_name')[0].childNodes[0].nodeValue);

I am using Firebug to help me debug. When I look at the DOM right after the page loads the childNodes part of my xmlDoc tree is empty, this explains why I get the error.
But why is it empty????!!!!!
It should have the xml structure in it.

To top it off, if I close the childNodes part of the tree (hide it) and then show it again by clicking the arrow to the left of it, Firebug finds everything!!!!!!!!!!!!!!!

All help is greatly appreciated!

XML File Example :
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <lab>
  3. <lab_name>My Lab</lab_name>
  4. <about>
  5. <description><![CDATA[A paragraph describing my lab!]]></description>
  6. <image>images/path/myimage.jpg</image>
  7. </about>
  8. </lab>
Javascript To Read It :
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. if (window.ActiveXObject)
  3. {
  4. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  5. xmlDoc.async=false;
  6. xmlDoc.load("xml/test_xml.xml");
  7. alert(xmlDoc.getElementsByTagName('lab_name')[0].childNodes[0].nodeValue);
  8. alert(xmlDoc.getElementsByTagName('description')[0].childNodes[0].nodeValue);
  9. alert(xmlDoc.getElementsByTagName('image')[0].childNodes[0].nodeValue);
  10. }
  11. // code for Mozilla, Firefox, Opera, etc.
  12. else if (document.implementation && document.implementation.createDocument)
  13. {
  14. xmlDoc = document.implementation.createDocument("", "", null);
  15. xmlDoc.load("xml/test_xml.xml");
  16. alert(xmlDoc.getElementsByTagName('lab_name')[0].childNodes[0].nodeValue);
  17. alert(xmlDoc.getElementsByTagName('description')[0].childNodes[0].nodeValue);
  18. alert(xmlDoc.getElementsByTagName('image')[0].childNodes[0].nodeValue);
  19. }
  20. // no good browser found
  21. else
  22. {
  23. if (!xmlDoc.load("xml/test_xml.xml"))
  24. {
  25. alert ("Failed to load XML data source!");
  26. }
  27. }
Apr 16 '07 #1
1 8096
dorinbogdan
839 Expert 512MB
Welcome to TheScripts TSDN....

Try this way:
Expand|Select|Wrap|Line Numbers
  1.         if (window.ActiveXObject)
  2.         {
  3.         xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  4.         xmlDoc.async=false;
  5.         xmlDoc.load("test_xml.xml");
  6.         testNodes();
  7.         }
  8.         // code for Mozilla, Firefox, Opera, etc.
  9.         else if (document.implementation && document.implementation.createDocument)
  10.         {
  11.         xmlDoc = document.implementation.createDocument("", "", null);
  12.         xmlDoc.load("test_xml.xml");
  13.         xmlDoc.onload = testNodes;
  14.         }
  15.         // no good browser found
  16.         else
  17.         {
  18.         if (!xmlDoc.load("test_xml.xml"))
  19.         {
  20.         alert ("Failed to load XML data source!");
  21.         }
  22.         }
  23.  
  24.     function testNodes(){
  25.         alert(xmlDoc.getElementsByTagName('lab_name')[0].childNodes[0].nodeValue);
  26.         alert(xmlDoc.getElementsByTagName('description')[0].childNodes[0].nodeValue);
  27.         alert(xmlDoc.getElementsByTagName('image')[0].childNodes[0].nodeValue);
  28.     }
  29.  
Apr 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: tagdance | last post by:
Hello friends, I have a very interesting problem with my css files and firefox - I guess ! Listen: I have set up my new website www.tagdance.de For testing purpose I have mirrored this...
7
by: Steven (remove wax and invalid for reply) | last post by:
I'm moving an old page to a new host, and trying to modernize it at the same time. There are two little problems that are driving me nuts. 1. Validation of www.marzolian.com/index.html says: ...
3
by: binnyva | last post by:
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...
3
by: cwdjrxyz | last post by:
I suggest that everyone using a recent version of Firefox read http://forums.mozillazine.org/viewtopic.php?t=315656&sid=b1db62861b8da29535c43e9c5c527c3b at once. This new security problem was...
2
by: Gary Coutts | last post by:
Hi, I am developing a website using Visual Studio .Net 2003. When reading offsetLeft, in a javascript function, the result is fine when run under I.E. but gives wrong results when run under...
1
by: paulnightingale | last post by:
Hi I've got a ticker tape that is written in Java Script 1.2 which displays text that has to be currently changed in the program code. What I want to do is to find the bit of javascript to get the...
34
by: Simon Wigzell | last post by:
document...focus() will scroll the form to move the specified text field into view on everything I have tried it with except Safari on the MAC. The form doesn't move. Any work around? Thanks.
4
by: charles | last post by:
Hello, I'm trying to use AJAX to send multipart data (not from a client file), and I'm using a requestbody with the files separated by a boundary, like that: var boundStr = 'capitano'; var...
9
by: giordan | last post by:
Hi, I'm new in this forum. I was searching for a solution to read xml file with javascript in Firefox (I hate this browser...grrrrr...) and I've found this topic. I've read all but my problem...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.