tags:

views:

304

answers:

4

i have a problem to access some file from different source. for example i have html folder and xml folder in same directory. then from html file i wanna access xml file in xml folder. in html i have script to call file xmlDoc=loadXMLDoc("../xml/note.xml");

why this path doesnt work as well?

this is my code of loadXmlDoc()

function loadXMLDoc(dname) 
{ 
   var xmlDoc; 

   if (window.XMLHttpRequest) 
   { 
       xmlDoc=new window.XMLHttpRequest(); 
       xmlDoc.open("GET",dname,false); 
       xmlDoc.send(""); 
       return xmlDoc.responseXML; 
   } // IE 5 and IE 6 
   else if (ActiveXObject("Microsoft.XMLDOM")) 
   { 
       xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); 
       xmlDoc.async=false; 
       xmlDoc.load(dname); 
       return xmlDoc; 
   } 

   alert("Error loading document"); 
   return null; 
}
A: 

The path is relative to the current page location (the current page you're browsing).

I suggest using the full http:// url, such as loadXMLDoc("http://example.com/xml/note.xml") or loadXMLDoc("/xml/note.xml").

Luca Matteis
+1  A: 

I would suggest using root relative, loadXmlDoc('/xml/note.xml') as this will always start at the same point ( the root ) and you don't have to keep ascending up with ../../.

meder
A: 

this is my code of loadXmlDoc()

function loadXMLDoc(dname) { var xmlDoc; if (window.XMLHttpRequest) { xmlDoc=new window.XMLHttpRequest(); xmlDoc.open("GET",dname,false); xmlDoc.send(""); return xmlDoc.responseXML; } // IE 5 and IE 6 else if (ActiveXObject("Microsoft.XMLDOM")) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load(dname); return xmlDoc; } alert("Error loading document"); return null; }

Post this as an edit to your question rather than posting as an answer.
rahul
I have edited for you.
rahul
A: 

You'll need to better describe what you mean by "doesn't work". However, judging from your code I'm guessing you are trying to get an XMLDOM object back from an XML source. Whenever I have trouble with XML sources I find the following list helps me track down my problem

Have you checked these things?

  1. Did you set your content type to text/xml?
  2. Is your request actually making it to the server and back?
  3. When you alert/examine the responseText, do you see anything that does not belong?
  4. Is your XML properly formatted? Run it through a validator.

With more information about what is failing I'll be better able to help.

Best of luck! Cheers.

coderjoe