Created
April 26, 2017 12:28
-
-
Save anonymous/03e92cdf612cfefc60a80189f1dcbe77 to your computer and use it in GitHub Desktop.
parse_xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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