3 ms·
In an XML document using namespaces, all tags and attributes are named with the tuple (namespace, name). Tags are always in the empty string namespace unless a
by jerf 3y ago
In an XML document using namespaces, all tags and attributes are named with the tuple (namespace, name).
Tags are always in the empty string namespace unless an explicit namespace prefix is given, in which case the tag's namespace in the one corresponding to the prefix.
That's it. That's all there is to namespaces and attributes. The idea is that the namespace would be redundant to the namespace on the tag, because the attribute's meaning is already 100% dependent on what tag it is on anyhow.
The big key to working with namespace documents in general is you have to understand that the names are now tuples (namespace, name), and that the string prefix you may see like "ns1" is an abbreviation, not the namespace. The namespace is the thing declared as the attribute of the xmlns tag. Get that right and most of the rest follows. What almost everything gets wrong is failing to treat names as (namespace, name) correctly, and trying to treat names as a single string like in non-namespaced document, and then writing in whatever misconceptions their particular implementation wrote in to get around the fundamental impossibility of handling a 2-tuple with an internal datastructure that is only a 1-tuple.
- cxr 3y ago> Tags are always in the empty string namespace unless an explicit namespace prefix is given, in which case the tag's namespace in the one corresponding to the prefix.¶ That's it. That's all there is to namespaces and attributes. This is at best misleading (or worse: misled—and wrong). The semantics of the following snippet is completely different: <foo:bar baz="xyzzy"/> ... from this: <foo:bar foo:baz="xyzzy"/> (Assume the "foo" prefix is defined and mapped to a namespace.) This is before even getting into the fact that unprefixed elements will belong to the default namespace (despite being written with no "explicit namespace prefix"). > The namespace is the thing declared as the attribute of the xmlns tag. The "xmlns tag"? No.