diff options
| author | Roger Peppe <rogpeppe@gmail.com> | 2015-06-29 12:36:48 +0100 |
|---|---|---|
| committer | roger peppe <rogpeppe@gmail.com> | 2015-06-30 07:42:37 +0000 |
| commit | bb7e665687d3a9bcbfd7814168a9f6e36d0e632b (patch) | |
| tree | 63582530479c138de9d1cc7d29e3cd101e479a7e /src/encoding/xml/xml.go | |
| parent | ab9c25f2de06e74cade453876835b3c1533a39de (diff) | |
| download | go-bb7e665687d3a9bcbfd7814168a9f6e36d0e632b.tar.xz | |
encoding/xml: fix xmlns= behavior
When an xmlns="..." attribute was explicitly generated,
it was being ignored because the name space on the
attribute was assumed to have been explicitly set (to the empty
name space) and it's not possible to have an element in the
empty name space when there is a non-empty name space set.
We fix this by recording when a default name space has been
explicitly set and setting the name space of the element to that
so printer.defineNS can do its work correctly.
We do not attempt to add our own xmlns="..." attribute
when one is explicitly set.
We also add tests for EncodeElement, as that's the only way
to attain coverage of some of the changed behaviour.
Some other test coverage is also increased, although
more work remains to be done in this area.
This change was jointly developed with Martin Hilton (mhilton on github).
Fixes #11431.
Change-Id: I7b85e06eea5b18b2c15ec16dcbd92a8e1d6a9a4e
Reviewed-on: https://go-review.googlesource.com/11635
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/encoding/xml/xml.go')
| -rw-r--r-- | src/encoding/xml/xml.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go index 3090750c48..ffab4a70c9 100644 --- a/src/encoding/xml/xml.go +++ b/src/encoding/xml/xml.go @@ -91,6 +91,12 @@ func (e *StartElement) setDefaultNamespace() { // or was just using the default namespace. return } + // Don't add a default name space if there's already one set. + for _, attr := range e.Attr { + if attr.Name.Space == "" && attr.Name.Local == "xmlns" { + return + } + } e.Attr = append(e.Attr, Attr{ Name: Name{ Local: "xmlns", |
