Skip to content

Commit

Permalink
Generarize riak_cs_xml:to_xml/1 to convert xmerl's simple form
Browse files Browse the repository at this point in the history
Add function clause to treat xmerl's simple forms.
http://www.erlang.org/doc/man/xmerl.html#export_simple-2

This function internally uses riak_cs_xml:format_value/1 so
atoms, intergers, lists and binaries are automatically converted
to lists (of Unicode codepoits, which xmerl accepts).
  • Loading branch information
shino committed Feb 12, 2014
1 parent 48be327 commit 84a821c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/riak_cs_xml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export_xml(XmlDoc) ->
-spec to_xml(term()) -> binary().
to_xml(undefined) ->
[];
to_xml([]) ->
[];
to_xml(SimpleForm) when is_list(SimpleForm) ->
simple_form_to_xml(SimpleForm);
to_xml(?ACL{}=Acl) ->
acl_to_xml(Acl);
to_xml(#acl_v1{}=Acl) ->
Expand All @@ -101,6 +101,21 @@ to_xml({users, Users}) ->
%% Internal functions
%% ===================================================================

%% @doc Convert simple form into XML.
simple_form_to_xml(Elements) ->
XmlDoc = format_elements(Elements),
export_xml(XmlDoc).

format_elements(Elements) ->
[format_element(E) || E <- Elements].

format_element({Tag, Elements}) ->
{Tag, format_elements(Elements)};
format_element({Tag, Attrs, Elements}) ->
{Tag, Attrs, format_elements(Elements)};
format_element(Value) ->
format_value(Value).

%% @doc Convert an internal representation of an ACL
%% into XML.
-spec acl_to_xml(acl()) -> binary().
Expand Down

0 comments on commit 84a821c

Please sign in to comment.