要生成如图格式的xml,怎么定义结构体呢?我定义的如下,但是有问题,不知道哪出了问题,有大神指导一下吗?
type Images struct {
Img string `xml:"img"`
Index int `xml:"index,attr"`
}
type Data struct {
OuterID string `xml:"outerID"`
Name string `xml:"name"`
Price float64 `xml:"price"`
Value float64 `xml:"value"`
// Saving float64 `xml:"saving"`
PriceUnit string `xml:"priceUnit"`
Availability int `xml:"availability"`
Image string `xml:"image"`
Brand string `xml:"brand"`
Loc string `xml:"loc"`
PcLoc string `xml:"pcLoc"`
SellerSiteUrl string `xml:"sellerSiteUrl"`
ShopName string `xml:"shopName"`
SearchWiseUrl string `xml:"searchWiseUrl"`
Category string `xml:"category"`
CategoryUrl string `xml:"categoryUrl"`
CategoryPcUrl string `xml:"categoryPcUrl"`
SubCategory string `xml:"subCategory"`
SubCategoryUrl string `xml:"subCategoryUrl"`
SubcategoryPcUrl string `xml:"subcategoryPcUrl"`
SellerName string `xml:"sellerName"`
Logo string `xml:"logo"`
MoreImages []Images `xml:"moreImages"`
Choice Attribute `xml:"choice"`
}
生成xml图片的代码片段如下:
_imgs := getImages(outerID)
if len(_imgs) <= 0 {
continue
}
_firstImg := ""
var _moreImages []Images
for i, v := range _imgs {
if i == 0 {
_firstImg = v
} else {
_moreImages = append(_moreImages, Images{Img: v, Index: i})
}
}
// fmt.Println(moreImages)
// os.Exit(1)
moreImages := _moreImages
subAttribute := []SubAttribute{SubAttribute{Key: "ext_down_load", Value: "https://m.mia.com/detail-a-" + outerID + ".html"}, SubAttribute{Key: "ext_put_url", Value: "https://m.mia.com/detail-a-" + outerID + ".html"}}
//Data数据
_choice := Attribute{Attribute: subAttribute}
itemData := Data{
OuterID: outerID,
Name: name,
Price: price,
Value: value,
PriceUnit: _PRICE_UNIT,
Availability: _AVAILABILITY,
Image: _firstImg,
MoreImages: moreImages,
Brand: brand,
Loc: _loc,
PcLoc: getPcLoc(outerID),
SellerSiteUrl: _SELLER_SITE_URL,
ShopName: _SHOP_NAME,
SearchWiseUrl: getSearchWiseUrl(outerID),
Category: category_id,
CategoryUrl: getCategoryUrl(category_id),
CategoryPcUrl: getCategoryPcUrl(category_id),
SubCategory: _categoryInfo["subCategoryId"],
SubCategoryUrl: getCategoryUrl(_categoryInfo["subCategoryId"]),
SubcategoryPcUrl: getCategoryPcUrl(_categoryInfo["subCategoryId"]),
Choice: _choice,
SellerName: _SELLER_NAME,
Logo: _LOGO}
生产xml的格式是这样的:
请问上述代码哪出了问题呢?
片段: