code: func (p *Decoder) typeForElement(val reflect.Value, start *StartElement) reflect.Type {
  	t := ""
  	for i, a := range start.Attr {
  		if a.Name == xmlSchemaInstance || a.Name == xsiType {
  			t = a.Value
  			// HACK: ensure xsi:type is last in the list to avoid using that value for
  			// a "type" attribute, such as ManagedObjectReference.Type for example.
  			// Note that xsi:type is already the last attribute in VC/ESX responses.
  			// This is only an issue with govmomi simulator generated responses.
  			// Proper fix will require finding a few needles in this xml package haystack.
  			// Note: govmomi uses xmlSchemaInstance, other clients (e.g. rbvmomi) use xsiType.
  			// They are the same thing to XML parsers, but not to this hack here.
  			x := len(start.Attr) - 1
  			if i != x {
  				start.Attr[i] = start.Attr[x]
  				start.Attr[x] = a
  			}
  			break
  		}
  	}
  
  	if t == "" {
  		// No type attribute; fall back to looking up type by interface name.
  		t = val.Type().Name()
  	}
  
  	// Maybe the type is a basic xsd:* type.
  	typ := stringToType(t)
  	if typ != nil {
  		return typ
  	}
  
  	// Maybe the type is a custom type.
  	if p.TypeFunc != nil {
  		if typ, ok := p.TypeFunc(t); ok {
  			return typ
  		}
  	}
  
  	return nil
  }
docs: // Find reflect.Type for an element's type attribute.