Thanks for reviewing. I don't know how you'd introduce a new prefix
other than with a tag, and tags are static and difficult to use on an
as-needed basis.
But the problem is really more about introducing existing prefixes
rather than new ones. Imagine you're emitting XML that's going to go
into the middle of an XML doc, and some prefixes have already been
declared in that doc. It would be clumsy to redeclare those prefixes, or
to declare new ones for the same namespaces. An XMPP implementation
almost requires this capability, and it's likely that other XMPP
implementations wouldn't interoperate with those clumsily redeclared
namespaces.
An XMPP conversation consists of two XML documents, each being sent the
opposite direction over the connection. The client's "document" starts
with this:
<stream:stream xmlns="jabber:client"
xmlns:stream="http://etherx.jabber.org/streams" ...>
Then, over the life of the connection, the client sends its commands to
the server as a series of XML elements, all of which are implicitly in
the "jabber:client" namespace. Notice there's no end tag for
<stream:stream>. That means you can't send it using xml.Marshal() or
xml.Encoder.Marshal() -- those both send end tags for every element. So
you have to output that <stream:stream> header without going through
Encoder. Somehow, Encoder needs to know that you've declared two namespaces.
I'm not in love with Context, but I don't see a better way to do it. A
full implementation of XML namespaces requires that you have something
functionally equivalent to Context. The ability to stop and start in the
middle of a document means we need to expose that information to the
user somehow.
Assuming you or somebody else doesn't see a better alternative to
Context, here's a related question: Should we use type aliases on the
keys and values of Context.Map? Currently it's map[string]string, and
Encoder uses it as namespace -> prefix while Decoder uses it as prefix
-> namespace. That feels dirty to me, and likely to cause confusion.
Chris
On 12/17/2012 9:19 AM, Russ Cox wrote:
I would like to drop Context from the API. Can we do that?
It seems to me that even if you're in the middle of a document you can
just introduce new prefixes as needed.
Russ