Skip to content

Instantly share code, notes, and snippets.

@nox
Created December 24, 2010 12:49
Show Gist options
  • Save nox/754223 to your computer and use it in GitHub Desktop.
Save nox/754223 to your computer and use it in GitHub Desktop.
expanded_name(Name, [], #xmlNamespace{default = URI}, S) ->
case is_name(URI, 'http://www.w3.org/XML/1998/namespace') of
true ->
?fatal(cannot_bind_default_namespace_to_xml_namespace_name, S);
false ->
case is_name(URI, 'http://www.w3.org/2000/xmlns/') of
true ->
?fatal(cannot_bind_default_namespace_to_xmlns_namespace_name, S);
false ->
{URI, Name}
end
end;
expanded_name(Name, N = {"xmlns", Local}, #xmlNamespace{nodes = Ns}, S) ->
{_, Value} = lists:keyfind(Local, 1, Ns),
XMLNSName = 'http://www.w3.org/XML/1998/namespace',
case is_name(Name, 'xmlns:xml') andalso not is_name(Value, XMLNSName) of
true ->
?fatal({xml_prefix_cannot_be_redeclared, Value}, S);
false ->
case is_name(Name, 'xmlns:xmlns') of
true ->
?fatal({xmlns_prefix_cannot_be_declared, Value}, S);
false ->
case is_name(Value, XMLNSName) of
true ->
?fatal({cannot_bind_prefix_to_xml_namespace, Local}, S);
false ->
case is_name(Value,
'http://www.w3.org/2000/xmlns/') of
true ->
?fatal({cannot_bind_prefix_to_xmlns_namespace, Local}, S);
false ->
N
end
end
end
end;
expanded_name(_Name, {Prefix, Local}, #xmlNamespace{nodes = Ns}, S) ->
case lists:keysearch(Prefix, 1, Ns) of
{value, {_, URI}} ->
{URI, string_to_name(Local, S)};
false ->
%% A namespace constraint of XML Names is that the prefix
%% must be declared
?fatal({namespace_prefix_not_declared, Prefix}, S)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment