Search code examples
javascriptxmlfeedoffline

How To Read ".XML" File Offline Using Pure JavaScript?


I am trying to read a .xml file that is a feed using pure JavaScript in my PC to show data on my browser. You can view my feed.xml file online that I saved from GoogleBlogXMLFeed. I can read that online via JSON but I want to read it offline after saving them in my file feed.xml in my PC. Is this possiable or not? If yes then any guideline...???


Solution

  • You can not access the "user" local file system from a web page. This would be a serious security issue (do you want web apps to be able to access files on your PC while you are browsing?).

    If you have the file on the same server with your app you can access it, just make sure you have the file extension in your mime-types.

    ----- adding the code based on comments -------

    $.ajax({
      url: "feed.xml", 
      success: function(xml){ 
        var xmlDoc = $.parseXML( xml ),
            $xml = $( xmlDoc ),
            title = $xml.find( "title" ).text();
        console.log(title);
      }
    });