Reputation: 11
erlang code:
-module(index).
-compile(export_all).
-include_lib("erlsom/include/erlsom.hrl").
start(Port) ->
misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end}]).
stop() ->
misultin:stop().
handle_http(Req) ->
Var = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><code>1</code><var1>123456</var1><var2>qwerty</var2></request>",
XmlErlsom = erlsom:simple_form(Var),
Req:ok("~s", [Var]).
After I compiled the code and started the server, I opened localhost:8080/ and the shell gave me the following error:
http process <0.196.0> has died with reason: {badarg,
[{erlang,list_to_binary,
[[{ok,
{"request",[],
[{"code",[],["1"]},
{"var1",[],["123456"]},
{"var2",[],["qwerty"]}]},
[]}]]},
The same lib 'erlsom' for ChicagoBoss worked successfully...
After that i try with xmerl, but the result is similar.
Upvotes: 0
Views: 218
Reputation:
erlsom:simple_form returns tuple of the form {ok, ParsedData}:
A = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><code>1</code><var1>123456</var1>`<var2>qwerty</var2></request>".
> erlsom:simple_form(A).
{ok,{"request",[],
[{"code",[],["1"]},
{"var1",[],["123456"]},
{"var2",[],["qwerty"]}]},
[]}
I believe you're trying to pass this returned tuple to Req:ok(), which expects list or binary or iodata or whatever else but tuple.
Upvotes: 1