encoding/xml: accept chains of interfaces and pointers

Fixes #6556.

R=golang-dev, iant, adg
CC=golang-dev
https://golang.org/cl/14747043
diff --git a/src/pkg/encoding/xml/marshal.go b/src/pkg/encoding/xml/marshal.go
index e723a19..d9522e0 100644
--- a/src/pkg/encoding/xml/marshal.go
+++ b/src/pkg/encoding/xml/marshal.go
@@ -354,18 +354,19 @@
 		return nil
 	}
 
-	kind := val.Kind()
-	typ := val.Type()
-
-	// Drill into pointers/interfaces
-	if kind == reflect.Ptr || kind == reflect.Interface {
+	// Drill into interfaces and pointers.
+	// This can turn into an infinite loop given a cyclic chain,
+	// but it matches the Go 1 behavior.
+	for val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr {
 		if val.IsNil() {
 			return nil
 		}
 		val = val.Elem()
-		typ = val.Type()
 	}
 
+	kind := val.Kind()
+	typ := val.Type()
+
 	// Check for marshaler.
 	if val.CanInterface() && typ.Implements(marshalerType) {
 		return p.marshalInterface(val.Interface().(Marshaler), defaultStart(typ, finfo, startTemplate))