Skip to content

Instantly share code, notes, and snippets.

@RadioactiveMouse
Created November 7, 2012 19:30
Show Gist options
  • Save RadioactiveMouse/4033829 to your computer and use it in GitHub Desktop.
Save RadioactiveMouse/4033829 to your computer and use it in GitHub Desktop.
XML parsing in Go
package main
import (
"fmt"
"encoding/xml"
"net/http"
"errors"
)
type Answer struct {
correct boolean
answer string
}
type Question struct {
question string
ask string
answerOne Answer
answerTwo Answer
answerThree Answer
answerFour Answer
}
func parseXML(input io.ReadWriter) ([]Question,error) {
output, err := xml.NewDecoder(Question).Decode(input)
if err != nil {
return nil, err
}
return output, nil
}
func main() {
res, err := http.Get("http://www.macs.hw.ac.uk/~pjbk/quiz/history.xml")
if err != nil {
log.Fatal("Error during GET request.")
}
res, er := parseXML(res)
if er != nil {
log.Fatal("Error during XML parsing")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment