title: JavaScript - AJAX : Accessing an XML File from a Server
body: <p>I am trying to access an XML file from a server in my javascript code.
  I have an XML file like this:</p>
  
  <pre><code>-&lt;stream version="1.2"&gt;
    -&lt;room id="simulator" time="128168557915"&gt;
     -&lt;dimention id=0 x="1.25" y="2.00"&gt;
       &lt;m mcu="160" sid="75"&gt;
      &lt;/dimention&gt;
     &lt;/room&gt;
  -&lt;room id="simulator" time="128168557928"&gt;
     -&lt;dimention id=0 x="1.95" y="1.86"&gt;
       &lt;m mcu="160" sid="55"&gt;
      &lt;/dimention&gt;
     &lt;/room&gt;
   &lt;/stream&gt;
  </code></pre>
  
  <p>this file is generated by an application and I can access it from a URL ( since I am using the simulator for this application the XML is accessible from <a href="http://localhost:8081/feed/demo" rel="nofollow noreferrer">http://localhost:8081/feed/demo</a>)
  This xml file is updated every few seconds and constantly growing.
  I have a javascript code which I've added the following code to it in order to use the data from XML file:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.open("GET","http://localhost:8081/feed/demo",false);
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML;
  document.write("&lt;table border='1'&gt;");
  var x=xmlDoc.getElementsByTagName("room");
  for (i=0;i&lt;x.length;i++)
    {
    document.write("&lt;tr&gt;&lt;td&gt;");
    document.write(xmlDoc.getElementsByTagName("dimention")[i].getAttribute("x"));
    document.write("&lt;/td&gt;&lt;td&gt;");
    }
  document.write("&lt;/table&gt;");
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Now here comes my problem: if I have the XML file saved on same drive as html page and I address it like this:
  xmlhttp.open("GET","floor.xml",false);
  it works fine, but when I pass the URL it doesn't. is there anything else I should do in case of loading the xml from URL?</p>
  
  <p>my second question is that I want to use the text values returned by </p>
  
  <pre><code>xmlDoc.getElementsByTagName("dimention")[i].getAttribute("x")
  </code></pre>
  
  <p>in an if statement like this :</p>
  
  <pre><code>if (valuereturned = 2.00)
  {
    do sth
  }
  </code></pre>
  
  <p>what is the best way to do that, since the returned value is a text.</p>
  
  <p>I need the answer ASAP and I realy appriciate your help :-)</p>