erlang代码:
-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]).
在我编译代码并启动服务器之后,我打开了localhost:8080 /并且shell给了我以下错误:
http process <0.196.0> has died with reason: {badarg,
[{erlang,list_to_binary,
[[{ok,
{"request",[],
[{"code",[],["1"]},
{"var1",[],["123456"]},
{"var2",[],["qwerty"]}]},
[]}]]},
ChicagoBoss的同一个lib'erlsom'成功运作......
之后我尝试使用xmerl,但结果类似。
答案 0 :(得分:1)
erlsom:simple_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"]}]},
[]}
我相信你试图将这个返回的元组传递给Req:ok(),它需要列表或二进制或者iodata或其他除了元组之外的其他元素。