Skip to content

Instantly share code, notes, and snippets.

@wardbekker
Created September 8, 2011 14:53
Show Gist options
  • Save wardbekker/1203600 to your computer and use it in GitHub Desktop.
Save wardbekker/1203600 to your computer and use it in GitHub Desktop.
Import XML file using Erlsom SAX parser
handle_call({import, FilePath}, _From, State) ->
{ok, Handle} = file:open(FilePath, [read, raw, binary]),
Position = 0,
Chunk = 1024,
CState = {Handle, Position, Chunk},
{ok, _Result, _TrailingBytes} =
erlsom:parse_sax(
<<>>,
undefined,
fun(Event, _Acc) -> sax_event(Event) end,
[{continuation_function, fun continue_file/2, CState}]
),
file:close(Handle),
Reply = ok,
{reply, Reply, State}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment