By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,542 Members | 953 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,542 IT Pros & Developers. It's quick & easy.

Script for accessing throught childNodes of XML file is not working in Firefox

P: 4
Hi everyone,

I have this code in javascript where the XML file is loaded and displayed to an html using XSLT. It works fine in IE but not in Firefox. My problem is in the looping to the childNodes. It seems that Firefox does not recognize this line of code >> xmlDoc.getElementsByTagName("urlValue")[ctr].childNodes[0].nodeValue

I'm not sure if this is the line that is not working, or the lines before it. I'm looping to the childNodes to compare to my generated code value and retrieve its equivalent text value so that the one displayed to the HTML is the text value by using the XSLT.

Here is the javascript code:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.  
  3. Load_XML("/SearchCenter/Documents/FOXindustries.xml");
  4. decodeValue("Findustry_");
  5.  
  6. function Load_XML(XMLfilePath) 
  7. { xmlDoc = ''
  8. if (window.ActiveXObject)
  9. { //IE 
  10. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  11. xmlDoc.async=false;
  12. xmlDoc.load(XMLfilePath); 
  13. alert("loadIE");
  14. return xmlDoc; 
  15. else if (document.implementation && document.implementation.createDocument)
  16. { //Firefox
  17. xmlDoc=document.implementation.createDocument("","",null);
  18. xmlDoc.load(XMLfilePath);
  19. alert("loadFF");
  20. return xmlDoc;
  21. }
  22. else
  23. {
  24. return '';
  25. }
  26. }
  27.  
  28. function decodeValue(Prop)
  29. var temp=''
  30. for (k=1; k<=20; k++)
  31. var temp=''
  32. var separator = ''
  33. if (document.getElementById(Prop_field.concat(k)) == null)
  34. { break;}
  35. codeValue = document.getElementById(Prop_field.concat(k)).innerHTML;
  36. multiCodeValue= codeValue.split(";");
  37. for (j=0;j<multiCodeValue.length;j++) 
  38. SingleCodeValue = multiCodeValue[j].split(" "); 
  39. for (x=0;x<SingleCodeValue.length;x++) 
  40. { ctr = 0; while (ctr < xmlDoc.documentElement.childNodes.length)
  41. {matchValue = xmlDoc.getElementsByTagName("urlValue")[ctr].childNodes[0].nodeValue;
  42. }
  43. if (SingleCodeValue[x] == matchValue)
  44. { if (temp!='' || separator != '' )
  45. temp = temp + separator + xmlDoc.getElementsByTagName("textValue")[ctr].childNodes[0].nodeValue;
  46. }
  47. else
  48. temp = xmlDoc.getElementsByTagName("textValue")[ctr].childNodes[0].nodeValue;
  49. separator = ", "
  50. }
  51. ctr++;
  52. }
  53. }
  54. }
  55. if (temp != '')
  56. {
  57. temp = temp.replace(/;/g, " ; ")
  58. document.getElementById(Prop_field.concat(k)).innerHTML = temp 
  59. }
  60. }
  61. }
  62. </script>
  63.  
Can anyone help me???

This code works fine in IE but not in Firefox...

What code will i use in order for this to work both in IE and Firefox.???
Jan 15 '08 #1
Share this Question
Share on Google+
2 Replies

jkmyoung
Expert 100+
P: 2,057
I'm not entirely sure, but I think you have your braces misplaced.
I don't think you should have your closing brace after
matchValue = xmlDoc.getElementsByTagName("urlValue")[ctr].childNodes[0].nodeValue;

Was this added accidentally?
Jan 15 '08 #2

P: 4
I'm not entirely sure, but I think you have your braces misplaced.
I don't think you should have your closing brace after
matchValue = xmlDoc.getElementsByTagName("urlValue")[ctr].childNodes[0].nodeValue;

Was this added accidentally?

Yes, this was accidentally added. It's not supposed to be there. I added several lines of codes before I posted it here. I forgot to delete this one... Thanks... Also, I wasn't able to edit Prop_field... its supposed to be Prop based on the argument passed.

Also, I debugged this code using the firebug and I noticed that the documentElement at the while loop contains NULL. Did I load the XML Document correctly?
Jan 16 '08 #3

Post your reply

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