FAQ
Resurrecting this old thread, because I've submitted a patch with a better
approach. http://codereview.appspot.com/6856092

I'm curious if anybody can come up with a better way to do this. My patch
notes include some problems, which I've expanded on below:

1. We can't add a new Prefix field to xml.Name, because it breaks source
compatibility. Programs written with xml.Name{"space", "local"} rather than
xml.Name{Space: "space", Local: "local"} will break.
2. Because of #1, there's no good way to load namespace context at runtime.
This is something you'd want to do if you were producing XML snippets to
stuff into the middle of an XML document, or if you were parsing snippets
excerpted from an XML document. The parent elements could have modified the
current namespace and the mapping of prefixes to URIs. It may be possible
to work around this deficiency by making a fake top-level container with
that namespace context, and then filtering that top-level container out
after the call to Marshal() or Unmarshal(), but it seems inelegant. The API
really ought to contain a graceful way to accomplish this.
3. Closely related to #2, there's no way to add a convenience prefix-to-URI
mapping. This could allow the parent element to define a namespace which it
doesn't use, but which all its children do. Otherwise, each child element
will redeclare xmlns="foo".

Chris

--

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 6 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 26, '12 at 3:04a
activeFeb 25, '13 at 4:56p
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase