loge.hixie.ch

Hixie's Natural Log

2006-06-29 20:20 UTC How to make namespaces in XML easier

I was thinking this morning about a possible extension to the Namespaces in XML spec that might make life easier for authors.

<html xmlns="import svg xbl html">
 ...
 <body>
  ...
  <svg>
   <rect .../>
  </svg>
 </body>
</html>

That is, add a new feature: the default namespace URI, if it starts with the string "import" followed by a space, is a space-separated list of keywords representing namespaces from which to look up each element. So in the example above, the "html" element is in the HTML namespace, the "body" element is too, the "svg" element is in the SVG namespace, and the "rect" element is in the SVG namespace. UAs would have a hardcoded list (given in the spec for this feature) of which element names are in which namespace, to make this possible. That way authors don't have to remember namespace URIs and they don't have to deal with namespace prefixes. Clashes would be solved by picking the first namespace in the author's list. Unknown elements would end up either in the last namespace specified, or the "" non-namespace, whichever way it was defined.

Alternatively we could have xmlns="web document", maybe, which would simply have the same effect but with a hard-coded list of namespaces and element names, so the authors don't even have to remember which languages to import. That would be less flexible, but the flexibility might not be needed.

The problem with this is how to introduce new element names; there'd be a long lag before people could start using them. That would be a reason to pick the namespace most likely to get new names as the default. Note that this wouldn't clash with existing usage of xmlns since you can't have a space in a valid namespace URI today.