Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read a local file in Elm?

Tags:

elm

I'm exploring the idea of replacing an XML->XSLT->HTML workflow with Elm, just to see if I can do it. I found an Elm XML parser, and now I just need to figure out how to read a local file into Elm. I can't seem to find anything anywhere that explains how to do that. How would I go about doing that?

like image 683
Jonathan Avatar asked May 20 '18 18:05

Jonathan


Video Answer


1 Answers

You can't directly read a file in Elm. Depending on your needs, you have a few options:

  1. If your program only needs access to a static file, you can read in the file with Javascript and provide it to Elm as a flag (see here). This is the simplest way if it meets your needs.
  2. If you need to react to changes in the file somehow, you could again read the file in with Javascript but communicate using ports (see here).
  3. A possibly-simpler variation would be to stand up a web server that serves the file, and then interact with it in elm using HTTP requests (see here).
like image 119
jacobm Avatar answered Sep 28 '22 10:09

jacobm