Value string ",chardata"
}
+type NameInField struct {
+ Foo Name `xml:"ns foo"`
+}
+
type AttrTest struct {
Int int `xml:",attr"`
Lower int `xml:"int,attr"`
UnmarshalOnly: true,
},
+ // xml.Name works in a plain field as well.
+ {
+ Value: &NameInField{Name{Space: "ns", Local: "foo"}},
+ ExpectXML: `<NameInField><foo xmlns="ns"></foo></NameInField>`,
+ },
+
+ // Marshaling zero xml.Name uses the tag or field name.
+ {
+ Value: &NameInField{},
+ ExpectXML: `<NameInField><foo xmlns="ns"></foo></NameInField>`,
+ MarshalOnly: true,
+ },
+
// Test attributes
{
Value: &AttrTest{
case reflect.Struct:
sv = v
typ := sv.Type()
+ if typ == nameType {
+ v.Set(reflect.ValueOf(start.Name))
+ break
+ }
tinfo, err = getTypeInfo(typ)
if err != nil {
return err
var tinfoMap = make(map[reflect.Type]*typeInfo)
var tinfoLock sync.RWMutex
+var nameType = reflect.TypeOf(Name{})
+
// getTypeInfo returns the typeInfo structure with details necessary
// for marshalling and unmarshalling typ.
func getTypeInfo(typ reflect.Type) (*typeInfo, error) {
return tinfo, nil
}
tinfo = &typeInfo{}
- if typ.Kind() == reflect.Struct {
+ if typ.Kind() == reflect.Struct && typ != nameType {
n := typ.NumField()
for i := 0; i < n; i++ {
f := typ.Field(i)