Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.