| Author |
Loading xml in Javascript fails
|
karthick ryan
Greenhorn
Joined: Jul 17, 2007
Posts: 19
|
|
Hi, The following piece of script does not work in jsp. Please let me know what could be the reason. var xmlObj; var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load("web.xml");//This xml file is present in the folder where the jsp file is present xmlObj = xmlDoc.documentElement; alert('obj '+xmlObj);// I get a null here Thanks!!
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Personally I would never load a XML filethat way. I would use the XMLHttpRequest Object. See if this helps you debug: http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html Eric
|
 |
karthick ryan
Greenhorn
Joined: Jul 17, 2007
Posts: 19
|
|
In your forum, .."I have talked about this in the past: http://radio.javaranch.com/pascarello/2005/10/26/113034827699 6.html, but I thought I would put some more information in how to debug this error. .." The above link does not work.. Can you please get me the sample code for the same. Please !!! [ August 02, 2007: Message edited by: karthick ryan ]
|
 |
karthick ryan
Greenhorn
Joined: Jul 17, 2007
Posts: 19
|
|
As per your suggestion, I used this : var xmlhttp loadXMLDoc('web.xml') function loadXMLDoc(url) { alert(url); xmlhttp=null // code for Mozilla, etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() } // code for IE else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") } if (xmlhttp!=null) { xmlhttp.onreadystatechange=state_Change xmlhttp.open("GET",url,true) xmlhttp.send(null) } else { alert("Your browser does not support XMLHTTP.") } } function state_Change() { // if xmlhttp shows "loaded" if (xmlhttp.readyState==4) { // if "OK" if (xmlhttp.status==200) { alert("XML data OK") } else { alert(xmlhttp.status); alert("Problem retrieving XML data:" + xmlhttp.statusText) } } } I get xmlhttp.status=404. Where is it searching for the XML file? I still have the problem.
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
|
As per your code, the web.xml file must be present in the root folder of your web application and not in any sub-directoty thereof. You mentioned the web.xml file was located in the same folder as the JSP file, right?
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
karthick ryan
Greenhorn
Joined: Jul 17, 2007
Posts: 19
|
|
|
Yes. The web.xml file is present inside the same folder as that of the JSP. Now is there anyway I can find the root directory path via javascript?
|
 |
karthick ryan
Greenhorn
Joined: Jul 17, 2007
Posts: 19
|
|
Pheeeeew... Its all done in terms of fetching the XML. Cooooool !!! I just put the web.xml file in the previous directory and used a "..\web.xml" to load the XML.. It works!!! Next job is to read the contents of the XML. Thank you to all javaranch.com people for helping me solve this one.
|
 |
 |
|
|
subject: Loading xml in Javascript fails
|
|
|