encoding/xml: name space bug fixes

If two fields have the same name but different explicit name spaces,
treat as non-conflicting. This allows parsing common XML formats
that have ns1:tag and ns2:tag in the same XML element.
Fixes #4691.

Allow setting the default name space for unadorned tags, by
writing to Decoder.DefaultSpace. This allows turned the job of
parsing common XML formats that have tag and ns2:tag in the
same XML element into the first case by setting DefaultSpace="ns1".
Fixes #3703.

Use name space attributes when decoding.
Attach name space to attributes when encoding.
Could be done with fewer annotations, but semantically correct as is.
Fixes #3526.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7227056
diff --git a/src/pkg/encoding/xml/marshal.go b/src/pkg/encoding/xml/marshal.go
index ea58ce2..3db8af0 100644
--- a/src/pkg/encoding/xml/marshal.go
+++ b/src/pkg/encoding/xml/marshal.go
@@ -120,6 +120,7 @@
 
 type printer struct {
 	*bufio.Writer
+	seq        int
 	indent     string
 	prefix     string
 	depth      int
@@ -210,6 +211,20 @@
 			continue
 		}
 		p.WriteByte(' ')
+		if finfo.xmlns != "" {
+			p.WriteString("xmlns:")
+			p.seq++
+			id := "_" + strconv.Itoa(p.seq)
+			p.WriteString(id)
+			p.WriteString(`="`)
+			// TODO: EscapeString, to avoid the allocation.
+			if err := EscapeText(p, []byte(finfo.xmlns)); err != nil {
+				return err
+			}
+			p.WriteString(`" `)
+			p.WriteString(id)
+			p.WriteByte(':')
+		}
 		p.WriteString(finfo.name)
 		p.WriteString(`="`)
 		if err := p.marshalSimple(fv.Type(), fv); err != nil {