diff --git a/src/pkg/encoding/xml/marshal_test.go b/src/pkg/encoding/xml/marshal_test.go index e0be3320086..0f6c0f0795d 100644 --- a/src/pkg/encoding/xml/marshal_test.go +++ b/src/pkg/encoding/xml/marshal_test.go @@ -532,6 +532,11 @@ var marshalTests = []struct { Value: &NameInField{Name{Space: "ns", Local: "foo"}}, ExpectXML: ``, }, + { + Value: &NameInField{Name{Space: "ns", Local: "foo"}}, + ExpectXML: ``, + UnmarshalOnly: true, + }, // Marshaling zero xml.Name uses the tag or field name. { diff --git a/src/pkg/encoding/xml/read.go b/src/pkg/encoding/xml/read.go index 871fe059cfa..3193cda7925 100644 --- a/src/pkg/encoding/xml/read.go +++ b/src/pkg/encoding/xml/read.go @@ -265,12 +265,13 @@ func (p *Decoder) unmarshal(val reflect.Value, start *StartElement) error { saveData = v case reflect.Struct: - sv = v - typ := sv.Type() + typ := v.Type() if typ == nameType { v.Set(reflect.ValueOf(start.Name)) break } + + sv = v tinfo, err = getTypeInfo(typ) if err != nil { return err