[erlang-questions] xmerl scan stream
Ulf Wiger
ulf@REDACTED
Mon Dec 8 23:09:39 CET 2008
Hi Peter,
Have you looked at the module xmerl_eventp in xmerl?
You might even be able to use it directly.
BR,
Ulf W
2008/12/8 Peter Sabaini <peter@REDACTED>:
> Hi list,
>
> I am trying to get xmerl to parse a stream of data coming in via a TCP socket.
> The goal would be for xmerl to return xmlRecords as soon as one is complete.
>
> I use the continuation function option of xmerl and so far that works ok;
> unfortunately I only get an xmlRecord as soon as the next xml element starts.
> Is there a way to tell xmerl to "evaluate eagerly"?
>
> Below is the test code I used; any help much appreciated. Is this even
> possible? Or am I completely on the wrong track and should use a SAX model
> instead?
>
> -- snip --
>
> -module(ap).
> -compile(export_all).
>
> start_server() ->
> {ok, Listen} = gen_tcp:listen(2345, [binary, {packet, raw},
> {reuseaddr, true},
> {active, true}]),
> spawn(fun() -> par_connect(Listen) end).
>
> par_connect(Listen) ->
> {ok, _Socket} = gen_tcp:accept(Listen),
> spawn(fun() -> par_connect(Listen) end),
> io:format("par_c ~n", []),
> X = xmerl_scan:string("", [{continuation_fun, fun continue/3}]),
> io:format("X: ~p ~n", [X]).
>
> continue(Continue, Exception, GlobalState) ->
> io:format("entered continue/3 ~n", []),
> receive
> {tcp, _Socket, Bin} ->
> Str = binary_to_list(Bin),
> io:format("got Str ~p ~n", [Str]),
> Continue(Str, GlobalState);
> {tcp_closed, _} ->
> io:format("Server socket closed~n" ),
> Exception(GlobalState)
> end.
>
> main() ->
> start_server().
>
>
> -- snip --
>
> --
> Peter Sabaini
> http://sabaini.at/
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list