[ejabberd] get_path

Stefan Strigler steve at zeank.in-berlin.de
Wed May 21 15:03:54 MSD 2008


Hello list,

along with xml:get_path_s wouldn't it be nice to have sth like this in
xml.erl:

get_path(El, []) ->
    El;
get_path(El, [{elem, Name} | Path]) ->
    case xml:get_subtag(El, Name) of
	false ->
	    false;
	SubEl ->
	    get_path(SubEl, Path)
    end;
get_path(El, [{attr, Name, Val} | Path]) ->
    case xml:get_tag_attr(Name, El) of
	{value, Val} ->
	    get_path(El, Path);
	_E ->
	    false
    end.


It allows to retrieve elements according to given path. Like

case get_path(El, [{elem, "x"}, {attr, "xmlns", ?MY_NS}, {elem, "foo"}]) of 
  false ->
    damn;
  El ->
    %% do sth with El
    ok
end



More information about the ejabberd mailing list