locked
[WP8.1]WP8 reading xml file: access is denied RRS feed

  • Question

  • Hello,

    In my HTML5 app for Windows Phone 8 I am trying to read xml file by xmlHttpRequest, but I am getting an error message: "Access is denied".

    Here is my code:

    var xmlhttp = new XMLHttpRequest();

    try{ xmlhttp.open("GET", "Data/file.xml", false);

    }

    catch(e){

    alert(e);

    } xmlhttp.setRequestHeader("Content-Type", "xml"); xmlhttp.send(); var result = xmlhttp.responseXML;

    I've tried $.ajax too, with the same negative result.

    How can I solve the problem?



    • Edited by leozel Friday, August 28, 2015 7:11 PM
    • Edited by Jamles Hez Monday, August 31, 2015 9:33 AM add titleg tag
    Friday, August 28, 2015 7:09 PM

Answers

  • Hello leozel,

    You need to use proper URI Scheme for accessing the local resources.

    Please see: How to load file resources (HTML)

     args.setPromise(WinJS.UI.processAll().then(function () {
                  
                  var xmlhttp = new XMLHttpRequest();
    
                  try {
                    xmlhttp.open("GET", "ms-appx:///Data/xmlfile.xml", false);
    
                  }
                  catch (e) {
                    alert(e);
                  }
                  
                  xmlhttp.send(null);
                  var status = xmlhttp.status; //check your status code should 200 for OK.
                  var xmlDoc = xmlhttp.responseXML;
                  var test = xmlDoc.getElementsByTagName("test");
                  new Windows.UI.Popups.MessageDialog(test[0].textContent).showAsync();
                }));

    Here is my xml called xmlfile.xml

    <?xml version="1.0" encoding="utf-8" ?> 
    <test>
      safds
    </test>
    

    Result

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, August 31, 2015 9:34 AM

All replies

  • Hello leozel,

    You need to use proper URI Scheme for accessing the local resources.

    Please see: How to load file resources (HTML)

     args.setPromise(WinJS.UI.processAll().then(function () {
                  
                  var xmlhttp = new XMLHttpRequest();
    
                  try {
                    xmlhttp.open("GET", "ms-appx:///Data/xmlfile.xml", false);
    
                  }
                  catch (e) {
                    alert(e);
                  }
                  
                  xmlhttp.send(null);
                  var status = xmlhttp.status; //check your status code should 200 for OK.
                  var xmlDoc = xmlhttp.responseXML;
                  var test = xmlDoc.getElementsByTagName("test");
                  new Windows.UI.Popups.MessageDialog(test[0].textContent).showAsync();
                }));

    Here is my xml called xmlfile.xml

    <?xml version="1.0" encoding="utf-8" ?> 
    <test>
      safds
    </test>
    

    Result

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, August 31, 2015 9:34 AM
  • Sorry, it's not an answer.
    Wednesday, September 9, 2015 10:01 AM