1

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; 
}
1
  • Can we see the code of your loadXMLDoc() function? Commented Jul 28, 2009 at 4:13

3 Answers 3

1

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 ../../.

Sign up to request clarification or add additional context in comments.

Comments

0

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").

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.