namespaces on the head of a pin

For purposes of discussion, here is what I think is a simple proposal
for namespace support in ixml.

1 Namespace declarations are allowed only before the first rule of the
grammar and apply throughout the grammar.  Syntax tbd, but for
discussion I'll assume

  nsdecl = 'declare', s, 'namespace', s, nsprefix, s, '=', nsname, s, '.'
  @nsprefix = NCName; '#default'.
  @nsname = -string.

If a prefix is bound more than once, it's an error (or: ...).

2 The current rule for 'name' is replaced by:

  @name: (prefix, ':')?, localname.
  -prefix: NCName.
  -localname: NCName.
  -NCName: namestart, namefollower*.

3 Prefixed nonterminals are serialized as QNames with appropriate
namespace bindings.  Unprefixed nonterminals follow the usual XML
convention: when serialized as elements, they are qualified with the
default namespace if any; when serialized as attributes they are not
namespace-qualified.

4 It is a dynamic error in the grammar if a prefixed name is serialized
for which the prefix lacks a namespace binding.

5 The LHS/RHS separator for rules changes from s, ["=:"], s to
s, ('=' | ':', ws), s. (Or: ...)

Example:

  declare namespace a = "http://example.com/nss/a".
  declare namespace #default = "http://example.org/nss.a".

  s = a:a, @a:b, c, @d.
  a:a = 'a'. a:b = 'b'. c = 'c'. d = 'd'.

  Input 'abcd'.
  XML:  <s xmlns="http://example.org/nss.a"
           xmlns:a="http://example.com/a"
           a:b="b" d="d">
           <a:a>a</a:a>
           <c>c</c>
        </s>

Since all namespace declarations are global, all namespace bindings can
be serialized in the XML on the document element, and the prefixes used
in the grammar can be used in the XML.

Known drawbacks:

  - No namespace undeclaration.
  - No local declarations, so we cannot embed unprefixed SVG in
    unprefixed XHTML by declaring a new default namespace on the svg
    element.

If this or a roughly equivalent mechanism for namespace binding is
available, then pragmas can use QNames to identify themselves.

If others in the group see reasons why something this simple cannot
work, I would be indebted to them for explaining those reasons to me.
The strongest argument I've heard so far is that users will want
additional control over choice of prefixes and want to play clever games
with prefix bindings.  Since I don't understand any of those games I
don't know how important it is to play them.

-- 
C. M. Sperberg-McQueen
Black Mesa Technologies LLC
http://blackmesatech.com

Received on Wednesday, 19 January 2022 01:32:10 UTC