troubleshooting Question

Loading an XML url with javascript.

Avatar of alainbryden
alainbrydenFlag for Canada asked on
Web Languages and StandardsJavaScriptXML
30 Comments1 Solution752 ViewsLast Modified:
Hey. I'm trying to create a small script that, when my page is visited, the script will run as follows:

1. It will load an url containing XML text ( )
2. It will read in certain values and if the sum of unemployment + (100 - transport) + criminality + pollution is equal to 0
3. It will automatically redirect the page with " window.location = ""; "

4. If the sum of the above is not 0, it will pick the largest of unemployment, (100 - transport), criminality and pollution, and redirect to, .../tra, .../sec or .../env respectively.

I have an ftp where I can upload and test the script, what I need are some people to help me pull the script together. Here is what I have attempted so far, but loading it does nothing, as the script is clearly flawed:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            <META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
            <title>Synthlight City</title>
<script type="text/javascript">
   var xmlDoc;
function importXML()
      if (document.implementation && document.implementation.createDocument)      {
            xmlDoc = document.implementation.createDocument("", "", null);
            xmlDoc.onload = createTable;
      else if (window.ActiveXObject)      {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.onreadystatechange = function ()      {
                  if (xmlDoc.readyState == 4) createTable()
      else      {
            alert('Your browser can\'t handle this script');
   var city = xmlDoc.getElementsByTagName("city");
   var unemployment = parseInt(city[0].getAttribute("unemployment"));
   var transport = parseInt(city[0].getAttribute("transport"));
   var criminality = parseInt(city[0].getAttribute("criminality"));
   var pollution = parseInt(city[0].getAttribute("pollution"));

   if (unemployment + (100 - transport) + criminality + pollution == 0)
      window.location = "";
   else if( (100 - transport) > unemployment && (100 - transport) > criminality && (100 - transport) > pollution )
      window.location = "";
   else if( unemployment > criminality && unemployment > pollution )
      window.location = "";
   else if( criminality > pollution )
      window.location = "";
      window.location = "";
You should be redirected to synthlight city automatically. If not, click <a href="">here</a>.

One thing I know for sure is that xmlDoc.load(""); does not work because that particular function expects a .xml file, not a url as a parameter.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 30 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 30 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros