javascript

Read local XML with JS  #angularjs #reactjs

  • I solved by simply embedding the XML file into the HTML using PHP.
  • At the moment, due to the security policy Chromium can not read local files via ajax without –allow-file-access-from-files .
  • If user is aware that local files are to be used by the application you can utilize element for user to upload file from user local filesystem, process file using FileReader , then proceed with application.
  • If you’re using Webpack, you can instead directly import the file using a loader like this or this , in which case the file is included into the resulting bundled javascript.
  • Once the flag is set, user can include element with rel=”import” attribute and href pointing to local file and type set to “application/xml” , for option other than XMLHttpRequest to get file.

At the moment, due to the security policy Chromium can not read local files via ajax without –allow-file-access-from-files. But I currently need to create a web application where the database is a xml-file (in the extreme case, json), located in one dir with index.html. It is understood that the user can run this application locally. Are there workarounds for reading xml- (json-) file, without wrapping it in a function and change to js extension?

@ng_real_ninja: Read local XML with JS #angularjs #reactjs

. But I currently need to create a web application where the database is a xml-file (in the extreme case, json), located in one dir with index.html. It is understood that the user can run this application locally. Are there workarounds for reading xml- (json-) file, without wrapping it in a function and change to js extension?

You can find the API through GOOGLE. Good luck.

If I understand correctly, the deliverable is intended to run locally so you will not be able to set any flags for local file access on a user’s machine. Something I’ve done in a pinch is to pack it up as an executable with something like nw.js and keep the external data files. Otherwise, you’re probably looking at loading as script using a JSON schema in a JS file.

I had a similar problem before. I solved by simply embedding the XML file into the HTML using PHP. Since the application is loaded locally from disk, size, cache etc. are not a concern.

If you’re using Webpack, you can instead directly import the file using a loader like this or this, in which case the file is included into the resulting bundled javascript.

flag set at chromium instance launch would require a substantial investment in trying workarounds to bypass content security policy of local filesystem.

By default, file:// URIs cannot read other file:// URIs. This is an override for developers who need the old behavior for testing.

. But I currently need to create a web application where the database is a xml-file (in the extreme case, json), located in one dir with index.html. It is understood that the user can run this application locally. Are there workarounds for reading xml- (json-) file, without wrapping it in a function and change to js extension?

, then proceed with application.

flag set. which can be done by creating a launcher for this purpose, specifying a different user data directory for the instance of chromium. The launcher could be, for example

See also How do I make the Google Chrome flag “–allow-file-access-from-files” permanent?

without creating a desktop launcher; where when the instance of chromium is closed run

to remove the configuration folder for the instance of chromium.

using

See Is there a way to know if a link/script is still pending or has it failed.

See

Or create or modify a chrome app and use

The simplest approach would be to provide a means for file upload by affirmative user action; process the uploaded file, then proceed with the application.

javascript

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.