No se puede analizar el archivo xml local con javascript

When i try to parse local xml file using simple javascript, the code after is not getting executed.

<script type="text/javascript">
function createXMLHttpRequestObject()
    if (window.XMLHttpRequest) {
      xhttp=new XMLHttpRequest();
    } else {
      xhttp=new ActiveXObject("Microsoft.XMLHTTP");

    return xhttp;

function makeRequest()
    var xhr = createXMLHttpRequestObject();

    try {"GET", 'books.xml', false);
    //xhr.onreadystatechange = function() {
     //if(this.readyState == 4) {
   } catch( err ) {
        alert("ERROR: " + err.description);
    <div onclick="makeRequest();">test<br></div>
    <div id="out">Output Here</div>

the books.xml file is as below,

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->


    <book category="COOKING">
      <title lang="en">Everyday Italian</title>
      <author>Giada De Laurentiis</author>

    <book category="CHILDREN">
      <title lang="en">Harry Potter</title>
      <author>J K. Rowling</author>

    <book category="WEB">
      <title lang="en">XQuery Kick Start</title>
      <author>James McGovern</author>
      <author>Per Bothner</author>
      <author>Kurt Cagle</author>
      <author>James Linn</author>
      <author>Vaidyanathan Nagarajan</author>

    <book category="WEB">
      <title lang="en">Learning XML</title>
      <author>Erik T. Ray</author>


When searched on internet i found that "For security reasons, modern browsers do not allow access across domains."

Por favor, ayuda.

preguntado el 08 de noviembre de 11 a las 11:11

3 Respuestas

Local files are best considered a no-go area. Security restrictions are pretty high. Run a web server on localhost instead and use that to access your page.

respondido 08 nov., 11:15

you may try to use a local web server to resolve the problem quickly.

respondido 08 nov., 11:15

Instead of setting web server on localhost....simply download aptana studio software and import your project in it...and run your html file, aptana directly open browser and automatically create web server with name

After that you will not receive any error.

respondido 08 nov., 11:15

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.