The two examples you give are not equivalent. A namespace is a URI, and such URIs can be bound to prefixes for defining fully-qualified names for elements and attributes. The URI does not need to point to an existing resource and XML processors are not expected to do any sort of resolution of the URI or otherwise create some canonical representation of it (apart from some attribute value normalization). Indeed, a namespace is actually little more than a case-sensitive string, but URIs just happen to have been chosen as their representation.
In other words, this
<element xmlns:ns1="xml" ns1:lang="fr" />
binds prefix ns1
to namespace xml
(which is not a legal URI reference). The lang
attribute is then in namespace xml
since it's qualified with the ns1
prefix.
So why is this not the same as your second example? Because in
<element xml:lang="fr" />
the xml
is the prefix, not the namespace. This prefix is implicitly bound to namespace http://www.w3.org/XML/1998/namespace
as per the specification regarding reserved prefixes and namespace names.
Look further into that spec and you'll also find that not only are you not allowed to bind the xml
prefix to any other namespace (makes sense) but you're also not allowed to bind the http://www.w3.org/XML/1998/namespace
namespace to any other prefix (makes less sense, but allows for some XML processing optimization and assumptions).
In conclusion, you should treat the first input as invalid if the xml:lang
attribute is required, because the attribute is not present in it. Whoever constructed that file has failed to understand XML namespaces.
I go more in-depth into the concepts in this answer.