Skip to content

Instantly share code, notes, and snippets.

Created April 26, 2017 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/03e92cdf612cfefc60a80189f1dcbe77 to your computer and use it in GitHub Desktop.
Save anonymous/03e92cdf612cfefc60a80189f1dcbe77 to your computer and use it in GitHub Desktop.
parse_xml
package main
import (
"fmt"
"os"
"encoding/xml"
)
type Rewards struct {
All []NameField `xml:",any"`
}
type NameField struct {
XMLName xml.Name `xml:""`
Value string `xml:",chardata"`
Attr string `xml:",any"`
}
func main() {
xmlFile, err := os.Open("path\\file.xml")
stat, _ := os.Stat("path\\file.xml")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer xmlFile.Close()
data := make([]byte, stat.Size())
xmlFile.Read(data)
var rewards Rewards
err = xml.Unmarshal(data, &rewards)
fmt.Println(rewards.All)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment