diff options
Diffstat (limited to 'src/encoding/xml')
| -rw-r--r-- | src/encoding/xml/marshal_test.go | 2 | ||||
| -rw-r--r-- | src/encoding/xml/typeinfo.go | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/encoding/xml/marshal_test.go b/src/encoding/xml/marshal_test.go index 601bb30d03..8362421db7 100644 --- a/src/encoding/xml/marshal_test.go +++ b/src/encoding/xml/marshal_test.go @@ -640,6 +640,8 @@ var marshalTests = []struct { `<x xmlns="space1">` + `<c>c1</c>` + `<d>d1</d>` + + `</x>` + + `<x>` + `<e>e1</e>` + `</x>` + `</top>`, diff --git a/src/encoding/xml/typeinfo.go b/src/encoding/xml/typeinfo.go index 22248d20a6..c9a6421f28 100644 --- a/src/encoding/xml/typeinfo.go +++ b/src/encoding/xml/typeinfo.go @@ -194,6 +194,14 @@ func structFieldInfo(typ reflect.Type, f *reflect.StructField) (*fieldInfo, erro return finfo, nil } + if finfo.xmlns == "" && finfo.flags&fAttr == 0 { + // If it's an element no namespace specified, get the default + // from the XMLName of enclosing struct if possible. + if xmlname := lookupXMLName(typ); xmlname != nil { + finfo.xmlns = xmlname.xmlns + } + } + // Prepare field name and parents. parents := strings.Split(tag, ">") if parents[0] == "" { |
