0

二郎代码:

-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,但结果相似。

4

1 回答 1

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 或除元组之外的任何其他内容。

于 2012-12-18T02:14:39.013 回答