anchor.diff:      #xmlel{name = <<"presence">>, children = Body};
   presence(Type, Body) ->
       #xmlel{name = <<"presence">>,
  -                attrs = [{<<"type">>, bin(Type)}],
  -                children = Body}.
  +           attrs = [{<<"type">>, bin(Type)}],
  +           children = Body}.
   
   presence_direct(Recipient, Type) ->
       presence_direct(Recipient, Type, []).
  
positive.code: %%--------------------------------------------------------------------
  
  stream_start(Server, XMLNS) ->
      #xmlstreamstart{name = <<"stream:stream">>, attrs=[
              {<<"to">>, Server},
              {<<"version">>, <<"1.0">>},
              {<<"xml:lang">>, <<"en">>},
              {<<"xmlns">>, XMLNS},
              {<<"xmlns:stream">>, <<"http://etherx.jabber.org/streams">>}]}.
  
  stream_end() ->
      #xmlstreamend{name = <<"stream:stream">>}.
  
  starttls() ->
      #xmlel{name = <<"starttls">>,
                  attrs=[
                      {<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-tls">>}
                  ]}.
  
  compress(Method) ->
      #xmlel{name = <<"compress">>,
                  attrs = [
                      {<<"xmlns">>, <<"http://jabber.org/protocol/compress">>}
                  ],
                  children = [
                      #xmlel{name = <<"method">>, children = [exml:escape_cdata(Method)]}
                  ]}.
  
  -spec iq(binary(), [xmlterm()]) -> #xmlel{}.
  iq(Type, Body) ->
      #xmlel{name = <<"iq">>,
                  attrs=[{<<"type">>, Type},
                         {<<"id">>, id()}],
                  children = Body}.
  
  iq(To, Type, Body) ->
      IQ = iq(Type, Body),
      IQ#xmlel{ attrs = [{<<"to">>, To} | IQ#xmlel.attrs] }.
  
  %% slightly naughty, this isn't a stanza but it will go in an <iq/>
  query_el(NS, Children) ->
          #xmlel{ name = <<"query">>,
                       attrs = [{<<"xmlns">>, NS}],
                       children = Children
                     }.
  
  %% http://xmpp.org/extensions/xep-0004.html
  %% slightly naughty - this isn't a stanza but can be a child of various stanza types
  x_data_form(Type, Children) ->
      #xmlel{ name = <<"x">>,
                   attrs = [{<<"xmlns">>,?NS_DATA_FORMS},
                            {<<"type">>, Type}],
                   children = Children
                 }.
  
  -spec bind(binary()) -> #xmlel{}.
  bind(Resource) ->
      NS = <<"urn:ietf:params:xml:ns:xmpp-bind">>,
      iq(<<"set">>, [
          #xmlel{name = <<"bind">>, attrs = [{<<"xmlns">>, NS}], children=[
              #xmlel{name = <<"resource">>, children=[exml:escape_cdata(Resource)]}
          ]}]).
  
  -spec session() -> #xmlel{}.
  session() ->
      NS = <<"urn:ietf:params:xml:ns:xmpp-session">>,
      iq(<<"set">>, #xmlel{name = <<"session">>, attrs = [{<<"xmlns">>, NS}]}).
  
  to(Stanza, Recipient) when is_binary(Recipient) ->
      setattr(Stanza, <<"to">>, Recipient);
  
negative.code: vcard([{_,_}|_] = Tuples) ->
      vcard(tuples_to_fields(Tuples));
  vcard(Body) ->
      #xmlel{name = <<"vCard">>,
             attrs = [{<<"xmlns">>,<<"vcard-temp">>}],
             children = Body}.
  
  cdata_field(Name, Value) ->
      #xmlel{name = Name,
             attrs = [],
             children = [{xmlcdata, Value}]}.
  
  field(Name, Children) ->
      #xmlel{name = Name,
             attrs = [],
             children = Children}.
  
  tuples_to_fields([]) ->
      [];
  