Should I be able to define a struct that contains a *string and uses this to unmarshal innerxml content.
See here for an example https://play.golang.org/p/oaGu0rKYNgi
I expect the Struct variable, Containment, to point to
<top xmlns="http://example.com/schema/1.2/config"/>
Instead it is nil.
I see similar example structs in src/encoding/xml/marshal_test.go
type IndirInnerXML struct {
T1 T1
InnerXML *string `xml:",innerxml"`
T2 T2
}
Any help much appreciated.
The test you quoted is for Marshal
, not for Unmarshal
. There is no test for *string
for innerxml for Unmarshal; there is one to prove that it won't work with []string
, and that it will work with []byte
and string
, but that's it. According to the docs for Unmarshal
:
If the struct has a field of type
[]byte
orstring
with tag",innerxml"
, Unmarshal accumulates the raw XML nested inside the element in that field. The rest of the rules still apply.
It supports []byte
and string
exclusively for unmarshalling inner XML. Whether *string
should be supported is a question for the Go maintainers.