【发布时间】:2021-07-26 23:38:38
【问题描述】:
EncodedData = xmpp:encode(Packet),
io:format("~n EncodedData => ~p~n", [EncodedData]),
{_, Id} = fxml:get_tag_attr(<<"id">>, EncodedData),
{_, To_Jid} = fxml:get_tag_attr(<<"to">>, EncodedData),
{_, From_Jid} = fxml:get_tag_attr(<<"from">>, EncodedData),
{_, Type} = fxml:get_tag_attr(<<"type">>, EncodedData),
如上所示,我能够成功地从 XML 读取数据。在某些情况下,Packet 中不存在 type 字段,因此 EncodedData 也没有 type 元素在其中,当我尝试访问该元素时,代码会因错误而崩溃
** exception error: no match of right hand side value false
in function mod_http_offline:create_message/1 (/opt/fp-backend-chat/ejabberd-modules/mod_http_offline.erl, line 38)
in call from ejabberd_hooks:safe_apply/4 (src/ejabberd_hooks.erl, line 236)
in call from ejabberd_hooks:run_fold1/4 (src/ejabberd_hooks.erl, line 217)
in call from ejabberd_sm:route/1 (src/ejabberd_sm.erl, line 146)
in call from ejabberd_router:do_route/1 (src/ejabberd_router.erl, line 399)
in call from ejabberd_router:route/1 (src/ejabberd_router.erl, line 92)
in call from ejabberd_c2s:check_privacy_then_route/2 (src/ejabberd_c2s.erl, line 865)
in call from xmpp_stream_in:process_authenticated_packet/2 (src/xmpp_stream_in.erl, line 714)
是否有任何方法可以找到访问元素是否存在于编码的 xml 中?
【问题讨论】: