我有一個像這樣的 XML 結構:<RootLevel status="new" timestamp="1383259529" xmlns="http://someplace.com"> <Item active="1" status="new" itemid="451254"> <SubItem active="1" recent="false" usertext="No idea" id="78421"> <SubItemField active="1" ready="no" type="1">1.4</SubItemField> <SubItemField active="1" ready="yes" type="2">4.5</SubItemField> </SubItem> </Item></RootLevel>我不知道如何收集 SubItemField 元素的值和屬性,我的代碼類似于:type RootLEvel struct { XMLName xml.Name `xml:"RootLevel"` ... Item []Item}type Item struct { ... SubItem []SubItem}type SubItem struct { ... SubItemField []SubItemField}type SubItemField struct { Active bool `xml:"active,attr"` Ready string `xml:"ready,attr"`}我需要屬性和值,但獲得我知道的值的唯一方法就是使用SubItemField []float32而不是我的自定義類型。我正在使用 xml.Unmarshal 順便說一句。任何想法?
- 1 回答
- 0 關注
- 428 瀏覽
添加回答
舉報
0/150
提交
取消