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

problem with reading XML-Document in Firefox

10
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 still exist! :-(

I report what I've wrote. The original script I've made is more complicated but the problem is the same, so I've tried with a smaller page. That's the source:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.     var xml;
  5. function test(){
  6.         // Load XML Explorer
  7.         if(window.ActiveXObject){
  8.             xml = new ActiveXObject("Microsoft.XMLDOM");
  9.             xml.async = false;
  10.             xml.load("casa.xml");
  11.             var prova = xml.selectSingleNode("prodotti/prodotto/codice[text() = 0001]");
  12.             var nome = prova.parentNode.selectSingleNode("titolo").text;alert(nome);
  13.         }
  14.         else{
  15.             if(document.implementation && document.implementation.createDocument){
  16.                 xml = window.document.implementation.createDocument("","",null);
  17.                 var caricamento = xml.load("casa.xml");
  18.                 xml.onload = readXML;
  19.                 //alert(xmlFile);
  20.             }
  21.         }
  22.     }
  23.         function readXML(){
  24.                 var toTry = xml.getElementsByTagName("prodotti")[0].childNodes[0].nodeValue;
  25.                 alert(toTry); // Result Empty Alert
  26.  
  27.         }
  28.  
  29.     </script>
  30. </head>
  31. <body onload="test()">
  32. <div id="test">
  33. </div>
  34. </body>
  35. </html>
I was trying to read from an XML file. In IE I have no problems, but Firefox don't want to read...
Some one coult help me or I have to carry Firefox to Primary School to learn how to read???

Thank you (and sorry for my English...I'm Italian...).

Giordan.
Dec 8 '07 #1
9 2041
gits
5,390 Expert Mod 4TB
hi ...

i assume your script is trying to read the first linebreak or whitespace and that has no nodeValue ... so try to alert the nodeName and post what you get :) ... its not firefox that makes the problem ... its the xml-file ...

kind regards
Dec 8 '07 #2
drhowarddrfine
7,435 Expert 4TB
Please be careful you are using proper DOM methods, too. Internet Explorer is almost 10 years behind current web standards for the DOM while all other browsers, including Firefox, are fairly up to date. Don't trust IE to be doing this properly.
Dec 8 '07 #3
rnd me
427 Expert 256MB
> selectsinglenode does not work in firefox.

---

my universal xml getter:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function IOx(U){
  3.  var X=((!window.XMLHttpRequest)?new ActiveXObject('Microsoft.XMLHTTP'):new     XMLHttpRequest() );
  4.     X.open('GET',U,false);
  5.     if(X.overrideMimeType) X.overrideMimeType( "text\/xml");
  6.     X.send('');    
  7.       var rx=X.responseXML;
  8.    if(rx) {return (rx.documentElement || rx ); };
  9. }//end iox
  10. IOx.txt="textContent"; if(document.all){IOx.txt="text"; }
  11.  
  12.  
  13. function test(fileURL){
  14.     var resp=IOx(fileURL);
  15.     var myNode resp.getElementsByTagName("prodotto")[0];
  16.     alert( myNode[IOx.txt]  );
  17. }//end function test
  18.  
  19. test("casa.xml");
  20.  
  21.  

use node[IOx.txt] to grab text across browsers.
Dec 9 '07 #4
giordan
10
Hi all,
thank you for the speedy-answer :-)
I've tried to ask the nodeName and Firefox answer me "#text".
I try to explain what I've done (and work properly in IE):
I have a shop, people can add what they like to a cart. When they end to shopping, going in Cart's page, they can buy what they have chosen.
Every time they add something to the cart, a cookie was added. I know every problem due to cookies, but it's not this the problem ;-)
When Cart's page is open, the cookies was read and, for every item, was opened the relative xml, found the product via id and extracted description and prize. All this values are memorized in many array. With a for loop was build via javascript a table with all values and put that in a empty div.

Well...firefox do all this step right but when it try to read xml file go boooom!

I post an example of xml that I use...it's nothing special...

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="windows-1252"?>
  2. <prodotti>
  3.     <prodotto disp="da ordinare">
  4.         <titolo>Spilla pesciolino</titolo>
  5.         <codice sezione="spille">0022</codice>
  6.         <immagine>http://www.naera.it/public/images/Shop/Spille/Spilla_pesciolino.jpg</immagine>
  7.         <ingrandimento>http://www.naera.it/public/images/Shop/Spille_Originali/Spilla_pesciolino.jpg</ingrandimento>
  8.         <descrizione>Spilla in cernit con pesciolino. Fornita di chiusura di sicurezza.</descrizione>
  9.         <prezzo>3,00€</prezzo>
  10.     </prodotto>
  11. </prodotti>
In the script I've posted I'm only trying to exctract "prodotti" node...

The steps I would do are:

1) found item whit XXXX code
2) go to parent node
3) select description and memorize the value in an array
4) select prize and memorize the value in an array

I thanks who posted XMLHTTPRequest method but...I don't know HTTPRequest and I think I spend much more time with that...
I've read that it's possible with alternative method...

Please help me...it's 3 days that I'm crashing my head to the wall!!!
Dec 9 '07 #5
giordan
10
Ok guys,
I've tried the XMLHTTPRequest method and it's near to work.
In Firefox work if the url isn't absolute, in IE work if it's absolute.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.     function IOx(U){
  5.  var X=((!window.XMLHttpRequest)?new ActiveXObject('Microsoft.XMLHTTP'):new     XMLHttpRequest() );
  6.     X.open('GET',U,false);
  7.     if(X.overrideMimeType) X.overrideMimeType( "text\/xml");
  8.     X.send(''); 
  9.       var rx=X.responseXML;
  10.    if(rx) {return (rx.documentElement || rx ); };
  11. }//end iox
  12. IOx.txt="textContent"; if(document.all){IOx.txt="text"; }
  13.  
  14.  
  15. function test(fileURL){
  16.         var nCount = 0;
  17.     var resp=IOx(fileURL);
  18.    while(resp.getElementsByTagName("prodotto")[nCount]){
  19.             var myNode = resp.getElementsByTagName("prodotto")[nCount].getElementsByTagName("codice")[0];
  20.             if(myNode[IOx.txt] == 0013){alert("entro");
  21.                 var myName = resp.getElementsByTagName("prodotto")[nCount].getElementsByTagName("titolo")[0];
  22.                 var nome = myName[IOx.txt];
  23.                 break;
  24.             }
  25.             else{
  26.                 alert('aggiungo');
  27.                 nCount++;
  28.             }
  29.  
  30.         }
  31.       alert( nome  );
  32. }//end function test
  33.  
  34. test("http://www.naera.it/public/xml/casa.xml"); //if try 'test("casa.xml")' it work properly.
  35.     </script>
  36. </head>
I've tried to put some 'alert' and I discovery that the problem is X.open
Before this line I have the alert, after no.

Someone could help me?

Thank you.
Dec 9 '07 #6
giordan
10
Hey!
Good news!
I've done what I wanted!
The problem?
This line:
Expand|Select|Wrap|Line Numbers
  1. IOx.txt="textContent"; if(document.all){IOx.txt="text"; }
Must become:
Expand|Select|Wrap|Line Numbers
  1. IOx.txt="textContent"; if(window.document.all){IOx.txt="text"; }
Thank you all!
Dec 9 '07 #7
drhowarddrfine
7,435 Expert 4TB
Do not use document.all .
Dec 9 '07 #8
acoder
16,027 Expert Mod 8TB
I was searching for a solution to read xml file with javascript in Firefox (I hate this browser...grrrrr...)
Oh wow! Most developers hold that opinion of IE. IE has a lot of bugs and quirks. Usually, if you have problems with reading XML in Firefox, you've coded for IE only and forgotten to account for whitespace when parsing.
Dec 10 '07 #9
gits
5,390 Expert Mod 4TB
yep ... as i said :) ... try to alert the nextSibling's nodeValue in FF ... i guess its the typical whitespace/linebreak-problem ... the xml-document shouldn't contain whitespaces and/or linebreaks ...

kind regards
Dec 10 '07 #10

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

Similar topics

5
by: Nick Shaw | last post by:
Hi, I'm trying to put my resume on my website, and I want to do it using XML and XSL. If I don't include the schema in the mix, the xml displays without a problem. When I add the schema...
9
by: Xarky | last post by:
Hi, I am writing an XML file in the following way. Now I need to read again that file to retrieve data such as Name and Age. Can someone help me out. Thanks in Advance ...
0
by: julio villalba | last post by:
Hi everyone im trying to generate an xml by reading a blank xml, with only the field description on it, and changing the values on that xml and saving it. im doing this by reading the xml with a...
3
by: Paul Bromley | last post by:
I have an application that needs to utilise an XML file produced by an external application. However I am having problems getting this into a Dataset using...
0
by: blabla120 | last post by:
Hi NG, I want to read a xml-file from an asp-page: // Kategorien aus xml laden string pathKategorien = Server.MapPath("./conf/kategorien.xml"); FileStream fs = new FileStream(pathKategorien,...
2
by: Barry | last post by:
Hi I have created the following class for reading XML Message from UPS, i use XMLSerializer to read the xml file , there is a minor problem , Response is a single item whereas RatedShipment is...
0
by: zahid | last post by:
hi, i am new o XML , i have a problem reading XML in ASP .the problem is the XML file has a <!DOCTYPE refering to external .dtd file when i remove this tag it works fine but when i add it it gives me...
1
by: Pathik | last post by:
Hi All, I have to get the values of "reading" and "value" elements of context Person/Category/Group/ser.These values must be on condition based,means I have to get the values of "reading" and...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.