anchor.diff:  
   -spec new_parser() -> {ok, parser()} | {error, any()}.
   new_parser() ->
  -    new_parser(single_doc).
  +    new_parser([]).
   
  --spec new_parser(parser_type()) -> {ok, parser()} | {error, any()}.
  -new_parser(Type)->
  +-spec new_parser([parser_opt()]) -> {ok, parser()} | {error, any()}.
  +new_parser(Opts)->
       try
           {ok, EventParser} = exml_event:new_parser(),
  -        {ok, prepare_parser(#parser{event_parser = EventParser, type = Type})}
  +        {ok, #parser{event_parser = EventParser,
  +                     config = #config{
  +                                 infinite_stream = proplists:get_value(infinite_stream, Opts, false),
  +                                 autoreset = proplists:get_value(autoreset, Opts, false)}
  +                    }}
       catch
           E:R ->
               {error, {E, R}}
  
positive.code:          parse/2,
           reset_parser/1,
           free_parser/1]).
  -export_type([parser/0]).
  -export_type([parser_type/0]).
  
  %% single_doc - the old way one document: <stream:stream> ..... </stream:stream>
  %% multiple_docs - xmpp over websockets(IETF 89) replaces <stream:..> tags with
  %% <open/> <close/>. As a result we have a stream of multiple xml documents instead of one document.
  %% This type of parser can handle that stream.
  %% see: http://datatracker.ietf.org/doc/draft-ietf-xmpp-websocket/?include_text=1
  -type parser_type() :: single_doc | multiple_docs.
  
  -record(parser, {
          event_parser,
          type,
          stack = []
  }).
  
  -type parser() :: #parser{}.
  
  
negative.code: 
  -spec parse(parser(), binary()) ->
          {ok, parser(), [xmlstreamelement()]} | {error, {string(), binary()}}.
  parse(#parser{event_parser = EventParser, stack = OldStack, config = Config} = Parser, Input) ->
      case exml_event:parse(EventParser, Input) of
          {ok, Events} ->
              {Elements, NewStack} = parse_events(Events, OldStack, [],
                                                  Config#config.infinite_stream),
              NewParser = if
                              NewStack =:= [] andalso Config#config.autoreset ->
                                  reset_parser(Parser);
                              true ->
                                  Parser
                          end,
              {ok, NewParser#parser{stack=NewStack}, Elements};
          {error, Msg} ->
              {error, {Msg, Input}}
      end.
  
  -spec reset_parser(parser()) -> {ok, parser()} | {error, any()}.
  reset_parser(#parser{event_parser = EventParser, config = Config}) ->
      try
          exml_event:reset_parser(EventParser),
          %% drop all the state except event_parser
          {ok, #parser{event_parser = EventParser, config = Config}}
      catch
          E:R ->
              {error, {E, R}}
  