go-xml
go-xml copied to clipboard
improve anonymous type handling
This PR introduces multiple improves in handling anonymous types:
coalesce identical anonymous types
old behaviour:
type Anon1 struct {
Elem []string `xml:"http://example.org/ Elem,omitempty"`
}
type Anon2 struct {
Elem []string `xml:"http://example.org/ Elem,omitempty"`
}
type ListType struct {
Elem []string `xml:"http://example.org/ Elem,omitempty"`
}
type Type1 struct {
ListType ListType `xml:"http://example.org/ ListType,omitempty"`
}
type Type2 struct {
ListType Anon2 `xml:"http://example.org/ ListType,omitempty"`
}
new behaviour:
type ListType struct {
Elem []string `xml:"http://example.org/ Elem,omitempty"`
}
type Type1 struct {
ListType ListType `xml:"http://example.org/ ListType,omitempty"`
}
type Type2 struct {
ListType ListType `xml:"http://example.org/ ListType,omitempty"`
}
remove dangling anon types
The elements in the xml tree would not be properly updated because children weren't stored as pointers. this left unused types in the final output (see Anon1 in the previous example).
use numbered names instead of Anon
If an anonymous type can't be named after the parent's attribute, then try with an integer suffix instead of naming it Anon. Eg. if ListType is already in use, the name the next anonymous type ListType1 (if the elements are not identical anyways).