%% @doc Тестовый модуль -module(test). -export([check/1, get_info/1]). -include_lib("xmerl.hrl"). %% @spec check(Pack::list()) -> ok | {error, Reason} %% @doc Функция проверки пакета check(P) -> try xmerl_scan:string(P) of Val -> {R,_} = Val, Tags = [xmerl_xpath:string("/body/" ++ T, R) || T <- ["data", "connect"]], case lists:any(fun(X) -> X =/= [] end, Tags) of false -> {error,unknown_pack_type}; true -> R end catch throw:X -> {error,X}; error:X -> {error,X}; exit:X -> {error,X} end. %% @spec get_info(Pack::list()) -> list() %% @doc Функция получения информации о пакете get_info(Pack) -> {R,_} = xmerl_scan:string(Pack), Tags = [xmerl_xpath:string("/body/" ++ T, R) || T <- ["data", "connect"]], [[D]] = lists:filter(fun(X) -> X =/= [] end, Tags), Data_type = atom_to_list(D#xmlElement.name), Prot = hd(xmerl_xpath:string("/body/header/protocol", R)), if Prot =/= [] -> Attrs = Prot#xmlElement.attributes, At = [{AA#xmlAttribute.name,AA#xmlAttribute.value} || AA <- Attrs]; true -> At = [] end, [{pack_type, Data_type}, {protocol, At}].