469,315 Members | 1,471 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Problems loading a local XML file with a local webpage

Hello,

I have designed a webpage mainly consisting in JavaScript code. It has to load an XML document's content when it is loaded so as to show a content depending on the XML data.

Both the HTML file and the XML file have to be stored locally on the computer and not on a server.

I only test in Internet Explorer, and the behaviour is very strange: on some machines, the XML file in well loaded, on some machines it isn't. I haven't seen this problem happening on IE6 and sometimes it happens on IE7, sometimes not... It happens under IE7 on my Vista Virtual Machine, It does not appear on my XP with IE6 and it does appear sometimes on XP with IE7 and sometimes not..
Here is the beginning of the function I use:

Expand|Select|Wrap|Line Numbers
  1. function loadFromXML()
  2. {
  3.     try
  4.     {
  5.         var request = null;
  6.         var xmlDoc = null;
  7.  
  8.         if (window.XMLHttpRequest) 
  9.         {
  10.             request = new XMLHttpRequest();
  11.                }
  12.  
  13.         else if (window.ActiveXObject) 
  14.         {
  15.                      request = new ActiveXObject("Microsoft.XMLHTTP");
  16.                }
  17.  
  18.                if (request) 
  19.         {
  20.             request.open("GET", "commentsDatas.xml"); 
  21.             request.onreadystatechange = function() 
  22.         {
  23.                  if (request.readyState == 4) 
  24.         {                                
  25.                     xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  26.             xmlDoc.loadXML(request.responseText);
  27.             var commentsList =    xmlDoc.getElementsByTagName("myComment");
...

If someone has an idea... I suspect that some security policy aspect is at stake but...
Thanks in advance!
Sep 18 '07 #1
7 8528
gits
5,390 Expert Mod 4TB
moved from js-articles section to js-forum ...
Sep 18 '07 #2
acoder
16,027 Expert Mod 8TB
Why use Ajax for reading the XML file?
Sep 19 '07 #3
What would you suggest instead?
Thanks
Sep 19 '07 #4
epots9
1,351 Expert 1GB
What would you suggest instead?
Thanks
read this Tutorial to find out how.

good luck
Sep 19 '07 #5
read this Tutorial to find out how.

good luck
Hi
That Link fails....might have been interesting too!
Sep 21 '07 #6
acoder
16,027 Expert Mod 8TB
Hi
That Link fails....might have been interesting too!
Are you sure? It works fine for me? Maybe the website was temporarily unavailable.
Sep 21 '07 #7
Thanks,
I'm going to have a look at this and I'll come back to tell if it fitted my needs.
Sep 21 '07 #8

Post your reply

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

Similar topics

4 posts views Thread by will | last post: by
2 posts views Thread by Jim Heavey | last post: by
4 posts views Thread by blackhawk | last post: by
1 post views Thread by CSTechie | last post: by
2 posts views Thread by TuftyTrue | last post: by
1 post views Thread by kevin.a.sweeney | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.