Help with parsing a string

So, I am trying to parse some blocks of text and extract the values for each block.

I was looking into Streams since the input is huge but not sure if they are a good fit here, never used them before.

I am currently splitting the input on a new row and trimming it, but not sure what to do next, what is the best way to split each block and associate the variables?

The input looks like this:

  def extract do
    input = 
      "<container>
      <article>
      value 1
      value 2
      </article>
      </container>
      <container>
      <article>
      value 1
      value 2
      </article>
      </container>"

    input
    |> String.split(~r/\n+/)
    |> Enum.map(fn x -> String.trim(x) end)
  end

Take a look at:

In the readme file there are examples for streaming as well. Check Streaming section.

2 Likes