• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loading xml in Javascript fails

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
karthick ryan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic