anchor.diff:  parse(XML, Opts) when is_binary(XML) ->
     parse(binary_to_list(XML), Opts);
   parse(XML, _Opts) when is_list(XML) ->
  -  {Document, _Rest} = xmerl_scan:string(XML),
  -  decode_document(Document).
  +  try
  +    {Document, _Rest} = xmerl_scan:string(XML, [{quiet,true}]),
  +    decode_document(Document)
  +  catch
  +    % functions are coded so they assume XML has proper structure
  +    error:function_clause ->
  +      {error, bad_xml_structure};
  +    error:{case_clause,_} ->
  +      {error, bad_xml_structure};
  +    error:{badmatch,_} ->
  +      {error, bad_xml_structure};
  +    % error coming from `xmerl_scan' module
  +    exit:{fatal,_} ->
  +      {error, bad_xml}
  +  end.
   
   %% @doc Parse XML message to request.
   %%
  
positive.code: decode_array(#xmlElement{content = ArrayData} = _V) ->
    #xmlElement{name = data, content = ValueList} = extract_child(ArrayData),
    Values = [
      decode_value_rec(extract_child(Vals)) ||
      #xmlElement{name = value, content = Vals} = _ValE <- ValueList
    ],
    Values.
  
  %% @doc Extract the single child from list of children (or throw an error).
  %%
  %%   Function clears any `#xmlText{}', leaving `#xmlElement{}' elements.
  %%
  %%   If result contains just one element, that element is returned. Otherwise,
  %%   function throws `{error, bad_xml_structure}' tuple.
  %%
  %% @spec extract_child([xml_node()]) ->
  %%   #xmlElement{}
  
negative.code: %%   Note that exception raised on server side is returned as a well-formed
  %%   XML response. This is `{ok, exception, ...}' case.
  %%
  %%   All the functions all the way down are coded so they die
  %%   ({@link erlang:error/1}) when error in XML was found, which indicates
  %%   protocol error. When the remote procedure failed, it is totally OK from
  %%   protocol point of view.
  %%
  %% @spec decode_document(XMLElement :: #xmlElement{}) ->
  %%     {ok, request,   xmlrpc_request()}
  %%   | {ok, result,    xmlrpc_result()}
  %%   | {ok, exception, xmlrpc_exception()}
  
  -spec decode_document(#xmlElement{}) ->
      {ok, request,   xmlrpc_request()}
    | {ok, result,    xmlrpc_result()}
    | {ok, exception, xmlrpc_exception()}.
  
  decode_document(#xmlElement{name = methodCall, content = Children}) ->
    % for method call, two children to expect: `<methodName/>' and `<params/>',
    % in any order(?)
    case [E || #xmlElement{} = E <- Children] of
      [#xmlElement{name = methodName, content = [#xmlText{value = Name}]},
        #xmlElement{name = params, content = Params}] ->
        ParamsDecoded = [
          % decode_value() doesn't catch "badly formed XML" tuples
          decode_value(extract_child(ValE)) ||
          #xmlElement{name = param, content = ParamE} = _P <- Params,
          #xmlElement{name = value, content = ValE}   = _V <- ParamE
        ],
        {ok, request, {list_to_binary(Name), ParamsDecoded}};
      [#xmlElement{name = params, content = Params},
        #xmlElement{name = methodName, content = [#xmlText{value = Name}]}] ->
        ParamsDecoded = [
          % decode_value() doesn't catch "badly formed XML" tuples
          decode_value(extract_child(ValE)) ||
          #xmlElement{name = param, content = ParamE} = _P <- Params,
          #xmlElement{name = value, content = ValE}   = _V <- ParamE
        ],
        {ok, request, {list_to_binary(Name), ParamsDecoded}}
    end;
  
  decode_document(#xmlElement{name = methodResponse, content = TopChildren}) ->
  