我需要輸出一個 XML 文件,并且我構建了一些表示它的結構作為一個基本示例,如下所示:type Parent struct { XMLName xml.Name `xml:"parent"` Name string `xml:"name,omitempty"` Age int64 `xml:"age,omitempty"` Child Child `xml:"child,omitempty`}type Child struct { XMLName xml.Name `xml:"child,omitempty"` Name string `xml:"name,omitempty"` Gender string `xml:"gender,omitempty"` Thoughts string `xml:",innerxml,omitempty"`}我希望當我創建一個Parent不定義子項,然后將其編組到一個 XML 文件中時......parent := Parent{ Name: "Beatrice", Age: "23",}_ = xml.MarshalIndent(parent, "", " ")...我應該得到一個不包含child標簽的 XML 文件:<parent> <name>Beatrice</name> <age>23</age></parent>相反,我得到這個:<parent> <name>Beatrice</name> <age>23</age> <child></child></parent>為什么空<child></child>標簽在那里,我怎樣才能擺脫它?
- 1 回答
- 0 關注
- 139 瀏覽
添加回答
舉報
0/150
提交
取消