1
私は、次のコードゴーXMLアンマーシャリング配列
// House struct used for houses xml file
type House struct {
XMLName xml.Name `xml:"houses"`
HouseID uint32 `xml:"houseid,attr"`
Name string `xml:"name,attr"`
EntryX uint16 `xml:"entryx,attr"`
EntryY uint16 `xml:"entryy,attr"`
EntryZ uint16 `xml:"entryz,attr"`
Size int `xml:"size,attr"`
TownID uint32 `xml:"townid,attr"`
Rent int `xml:"rent,attr"`
}
// LoadHouses parses the server map houses
func LoadHouses(file string, list []House) error {
// Load houses file
f, err := ioutil.ReadFile(file)
if err != nil {
return err
}
// Unmarshal houses file
return xml.Unmarshal(f, &list)
}
これは、任意のエラーを返していないと、この
<?xml version="1.0" encoding="UTF-8"?>
<houses>
<house name="Rhyves Flats 14" houseid="1" entryx="167" entryy="361" entryz="6" rent="0" townid="2" size="17" />
</houses>
のように見えるファイルを非整列化しようとしています。しかし、家のスライスは空です。すべて正しいと思われ、attrsが設定され、XMLNameも設定されます。