How to omit a field in xml

I have a structure

type UserData struct {
 SomeData struct {
	AnotherData []struct {
		Data1  string  `xml:"pair1" json:"pair1"`
		Data2  string  `xml:"pair2" json:"pair2"`
		Data3   float64 `xml:"rate" json:"rate"`
		InnerData struct {
			InnerData1  float64 `xml:"inner1" json:"inner1"`
			InnerData2 float64 `xml:"inner2" json:"inner2"`
		} `xml:"innerdata" json:"innerdata"`
	} `xml:"anotherdata" json:"anotherdata"`
  } `json:"somedata" xml:"somedata"`
} 

when I marshal this struct to xml
I get the following output

<userData>
  <someData>
    ...
  </someData>

How can I omit userData, the xml should start with someData not with userData

 <someData>
    ...
  </someData>

You can marshal the inner SomeData field directly.

var d UserData = ...
bs, err := xml.Marshal(&d.SomeData)

I got an error xml: unsupported type: struct

OK, so give the type a name;

https://play.golang.org/p/7X2TY25AqZ6

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.