type XMLShop struct {
XMLName xml.Name `xml:"shop"`
Name string `xml:"name"`
Company string `xml:"company"`
Url string `xml:"url"`
Categories []*XMLShopCategories `xml:"categories>category"`
}
package main
import (
"encoding/xml"
"fmt"
)
type XMLShop struct {
XMLName xml.Name `xml:"shop"`
Name []NameField `xml:",any"`
Company string `xml:"company"`
Url string `xml:"url"`
}
type NameField struct {
XMLName xml.Name `xml:""`
Value string `xml:",chardata"`
}
const data = `
<shop>
<someOtherName>testname1</someOtherName>
<custom_name>testname2</custom_name>
<company>testcorp</company>
<url>http://ya.ru</url>
</shop>
`
func main() {
var shop XMLShop
if err := xml.Unmarshal([]byte(data), &shop); err != nil {
fmt.Println(err)
return
}
for _, node := range shop.Name {
if node.XMLName.Local == "custom_name" {
fmt.Printf("Name: %+v\n", node.Value)
}
}
}