Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

loading xml with JavaScript not working

843840Oct 6 2008 — edited Oct 7 2008
I've got some setting somewhere that must be missing because I just can't get an xml file to load via JavaScript - I'm using the Spring & Tiles framework - I've tried all sorts of tips and techniques but my document object is always null - below is the simplest example I could find that should work but doesn't - I've tried changing the xml location from "music.xml" to just about everywhere on the server, but always get the same results

example xml file:
<?xml version="1.0" encoding="ISO8859-1" ?>
<NewDataSet>
    <CD>
        <Name>Music</Name>
    </CD>
    <CD>
        <Name>Politics</Name>
    </CD>
    <CD>
        <Name>Shopping</Name>
    </CD>
</NewDataSet>
jsp tile:
<script type="text/javascript"><!--
/* <![CDATA[ */
var xmlDoc;
var genrename;
window.onload=loadXmlDoc;

function loadXmlDoc()
{    
	  if (window.ActiveXObject)
	    {
	        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	        xmlDoc.async=false;
	        xmlDoc.load("music.xml");
	        LoadOptions();    
	    }
	    else if (document.implementation && document.implementation.createDocument)    
	    {
	        xmlDoc = document.implementation.createDocument("","",null);
	        xmlDoc.onload = LoadOptions();
	        xmlDoc.load("music.xml");
	    }
}

function LoadOptions()
{
  genrename = xmlDoc.getElementsByTagName("Name");
  for (var i=0; i<genrename.length; i++)
  {
      document.forms['genreform'].genre.options[i] = new Option(genrename.firstChild.nodeValue,genrename[i].firstChild.nodeValue);
}
}

/* ]]> */
--></script>

<form name="genreform">
<select name="genre" >
<option value="Test"> Testing</Option>
</select>
</form>
<div id = "box" style= "background:yellow;width:320px;padding:5px"> </div>
Edited by: GrandVizier on Oct 7, 2008 3:48 PM

for what its worth - the only error message I get is: 'xmlDoc is undefined'

and when I place
alert(xmlDoc.documentElement);
in various places in the code I just get 'null'

I set up
<img src="images/delete.png" />
and changed it to
xmlDoc.load("images/music.xml");
which shows my image but still doesn't load the xml

I'm using Apache Tomcat 6.0.18 if that helps track this down                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 4 2008
Added on Oct 6 2008
5 comments
216 views