anchor.diff:  -include("subscriptions/subscriptions.hrl").
   -include_lib("datastore/oz_datastore_models_def.hrl").
   -include_lib("ctool/include/test/test_utils.hrl").
  +-include_lib("xmerl/include/xmerl.hrl").
  +
   
   %% API
   -export([set_config/1, check_rest_call/1]).
  
positive.code:         end,
          ReqAuth = maps:get(auth, RequestMap, undefined),
          ReqOpts = maps:get(opts, RequestMap, []),
  
          ExpCode = maps:get(code, ExpectMap, undefined),
          ExpHeaders = maps:get(headers, ExpectMap, undefined),
          ExpBody = maps:get(body, ExpectMap, undefined),
  
          URL = str_utils:join_binary([get_random_oz_url() | ReqPath], <<"">>),
          HeadersPlusAuth = case ReqAuth of
              undefined ->
                  ReqHeaders;
  
negative.code:                 _ ->
                      MapAcc
              end
          end, OriginalMap, maps:keys(OriginalMap)).
  
  compare_xml(#xmlText{value=V}, #xmlText{value=V}) -> true;
  compare_xml(#xmlText{value=_V1}, #xmlText{value=_V2}) -> false;
  compare_xml(#xmlAttribute{name=N, value=V}, #xmlAttribute{name=N, value=V}) -> true;
  compare_xml(#xmlAttribute{name=_N1, value=_V1}, #xmlAttribute{name=_N2, value=_V2}) -> false;
  compare_xml(#xmlElement{name=Name, attributes=_, content=_},
              #xmlElement{name=Name, attributes=[], content=[]}) -> true;
  compare_xml(#xmlElement{name=Name, attributes=RespAttributes, content=RespContent},
              #xmlElement{name=Name, attributes=ExpAttributes, content=ExpContent}) -> %TODO match name
  
      ct:pal("COMPARE_XML: ~p~n", [Name]),
      case compare_xml(RespAttributes, ExpAttributes) of
          false -> false;
          true -> compare_xml(RespContent, ExpContent)
      end;
  %%    ct:pal("ATTRS: ~p~n~p", [ExpAttributes, RespAttributes]),
  
  %%    MatchAttrs = compare_xml(RespAttributes, ExpAttributes),
  
  %%    MatchAttrs = lists:foldl(fun(ExpA=#xmlAttribute{name=N}, Acc) ->
  %%        case lists:keyfind(N, 2, RespAttributes) of
  %%            false -> false;
  %%            RespA = #xmlAttribute{} -> Acc and compare_xml(RespA, ExpA);
  %%            _ -> false
  %%        end
  %%    end, true, ExpAttributes),
  
  %%    ct:pal("MatchAttrs = ~p~n", [MatchAttrs]),
  
  %%    ct:pal("CONTENT: ~p~n~p", [ExpContent, RespContent]),
  
  compare_xml(RespAttributes, [ExpA = #xmlAttribute{name=N} | ExpAttributesRest]) ->
      case lists:keyfind(N, 2, RespAttributes) of
          RespA = #xmlAttribute{} ->
              compare_xml(RespA, ExpA) and compare_xml(RespAttributes, ExpAttributesRest);
          _ -> false
      end;
  compare_xml(RespContent, [#xmlText{value=V} | ExpContentRest]) ->
      case lists:keyfind(V, 5, RespContent) of
          #xmlText{} ->
              compare_xml(RespContent, ExpContentRest);
          _ -> false
      end;
  compare_xml(RespContent, [ExpC = #xmlElement{name=N} | ExpContentRest]) ->
      case lists:keyfind(N, 2, RespContent) of
          RespC = #xmlElement{} ->
              compare_xml(RespC, ExpC) and compare_xml(RespContent, ExpContentRest);
          _ -> false
      end;
  compare_xml(_, []) -> true;
  compare_xml(_, _) -> false.
  
  
  
  %%filter(List = [#xmlText{} | _], _) -> List;
  %%filter([A = #xmlAttribute{name=Name}], AttributesToBeChecked) ->
  %%    case lists:member(Name, AttributesToBeChecked) of
  %%        true -> [A];
  %%        _ -> []
  %%    end;
  %%filter([A = #xmlAttribute{} | Rest], AttributesToBeChecked) ->
  %%    filter([A], AttributesToBeChecked) ++ filter(Rest, AttributesToBeChecked);
  %%filter([E = #xmlElement{name=Name}], MatchPrecisionContent) ->
  %%    ElementsToBeChecked = maps:keys(MatchPrecisionContent),
  %%    case lists:member(Name, ElementsToBeChecked) of
  %%        true -> [E];
  %%        _ -> []
  %%    end;
  %%filter([E = #xmlElement{} | Rest], MatchPrecisionContent) ->
  %%    filter([E], MatchPrecisionContent) ++ filter(Rest, MatchPrecisionContent).
  %%
  %%
  %%%%filter(ListXML, MatchPrecision) ->
  %%%%    lists:filter(fun(E) ->
  %%%%        case E of
  %%%%            #xmlElement{name=Name} ->
  %%%%                ok;
  %%%%            #xmlAttribute{name=Name} ->
  %%%%                maps:get()
  %%%%            #xmlText{} -> true
  %%%%        end
  %%%%    end, ListXML).
  %%
  %%zip(ListXML1, ListXML2) ->
  %%    ct:pal("ListXML1:~n~p", [ListXML1]),
  %%    ct:pal("ListXML2:~n~p", [ListXML2]),
  %%    ct:pal("SORT1:~n~p", [lists:sort(fun sort_xml/2, ListXML1)]),
  %%    ct:pal("SORT2:~n~p", [lists:sort(fun sort_xml/2, ListXML2)]),
  %%    lists:zip(lists:sort(fun sort_xml/2, ListXML1), lists:sort(fun sort_xml/2, ListXML2)).
  %%
  %%sort_xml(#xmlText{}, #xmlText{}) -> true;
  %%sort_xml(#xmlAttribute{name=Name1}, #xmlAttribute{name=Name2}) -> Name1 =< Name2;
  %%sort_xml(#xmlElement{name=Name1}, #xmlElement{name=Name2}) -> Name1 =< Name2;
  %%sort_xml(X, Y) -> ct:pal("MATCHED: ~p~n~p", [X, Y]).