Hey Elixir Forum. This is my first time using Elixir for actual professional use, and not just messing around with it in my own free time.
So, basically I’m recursively going through an entire directory of sub-directories. I’m saving all of the file paths in those directories as a list. I take that list of files and parse the xml value I want out of them. I store this as a map of :filename => [xml-values]. It’s important I have the filename associated with the value. From here I want to write my map that I created to a file. I don’t really have a preference at this point because I’ve gotten very frustrated. I just need it human readable. JSON, CSV, text . . . doesn’t matter. How in the world can I the entire directory of xml values to a file while avoiding overwriting the file & while avoiding storing the XML values as binary? I’ve been trying IO.write & File.write in many many different variations.
Here is a bit of the code:
def read do
files = list_all("/my/files/path/right/here/right/now")
for file <- files do
doc = File.read!(file)
xml = doc |> xpath(~x"//MeshGeometry3D/@x:Key"l)
list_prefix = %{file => xml}
end
Thanks for any replies. This morning I felt confident I had this problem in the bag. Now I’m exhausted just looking at it.
You aren’t actually trying to write something. I’d suggest showing us some code where you try to write a file. Also I think it might be useful if you tell us which library you use for xml parsing.
Ah, my mistake. I’m using SweetXML to parse the xml.
def write do
myfile = read()
File.write("/my/file/path/here/access_components", myfile)
end
I had a different solution where I was closer, but I suspect the map I created keeps overwriting itself with new values. I get confused because if I IO.inspect inside that loop it looks like it is doing what I want in that it writes thousands of lines with %{filename => [list_values]}.
This doesn’t work so well because it stops using the filename as the key and just puts “file” as the key. Or it will error out saying “file” must be an atom.
Can you give me part of code to fetch xml values and example file (not with real data) so I will give you full example script? I did not worked yet with xml files.
Ohhhh, very nice! You have been so patient and nice with me! I remember when I very very first started to learn programming a few years ago everyone was difficult (stackoverflow). Thank you so much. This is my first month of functional programming so I know my code might have been difficult to look at. I think your solution will really help me out!