「github.com/guregu/null」パッケージを利用できます。助けになる:
package main
import (
"fmt"
"encoding/xml"
"github.com/guregu/null"
)
type Items struct{
It []Item `xml:"Item"`
}
type Item struct {
DealNo string
ItemNo null.Int
Name string
Price null.Float
Quantity null.Float
Place string
}
func main(){
data := `
<Items>
<Item>
<DealNo/>
<ItemNo>32435</ItemNo>
<Name>dsffdf</Name>
<Price>135.12</Price>
<Quantity></Quantity>
<Place>dsffs</Place>
</Item>
<Item>
<DealNo/>
<ItemNo></ItemNo>
<Name>dsfsfs</Name>
<Price></Price>
<Quantity>1.5</Quantity>
<Place>sfsfsfs</Place>
</Item>
</Items>`
var xmlMsg Items
if err := xml.Unmarshal([]byte(data), &xmlMsg); err != nil {
fmt.Println("Error: cannot unmarshal xml from web ", err)
} else {
fmt.Println("XML: ", xmlMsg)
}
}