0

My goal is to read in a file test.xml which is in the same folder as my index.html.

I know that I can pull in script files with something like <script src="index.js></script>, but is there a way for me to do the same with an xml file <xml src="test.xml"><xml>.

I do not want to use the AJAX XMLHttpRequest because the index.html may not be hosted on an http server, but instead opened like a normal file in chrome.

Do I have any options when it comes to opening up this xml file, or will it have to be hosted on a http server? I guess another option would be to store the whole xml file inside of a javascript variable, but this seems unnecessary.

user1634494
  • 609
  • 1
  • 7
  • 23

1 Answers1

0

do not want to use the AJAX XMLHttpRequest because the index.html may not be hosted on an http server, but instead opened like a normal file in chrome.

Try launching chrome with --allow-file-access-from-files flag set . Should then be able to use XMLHttpRequest to retrieve file in local filesystem

*nix

/usr/bin/google-chrome --allow-file-access-from-files

*indows

start chrome --allow-file-access-from-files

See How do I make the Google Chrome flag “--allow-file-access-from-files” permanent? , Opening Chrome From Command Line

Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177
  • This is still pretty sub-ideal for what I am trying to do. I mentioned chrome in my example, but to me it is unknown what browser will be used to access this html file. Also, I don't want to force someone to enable a flag in order to use the html file. – user1634494 Nov 16 '15 at 21:40
  • _"This is still pretty sub-ideal for what I am trying to do. I mentioned chrome in my example, but to me it is unknown what browser will be used to access this html file. Also, I don't want to force someone to enable a flag in order to use the html file."_ ? Not exactly certain what "trying to do" consists of ? If requirement is _"read in a file test.xml which is in the same folder as **my** index.html"_ , would not "force someone" else to enable a flag , as would be local file at _your_ local filesystem ? – guest271314 Nov 16 '15 at 23:38
  • Can include more details describing requirment at Question ? – guest271314 Nov 16 '15 at 23:44