Skip to content

Instantly share code, notes, and snippets.

@stephenwithav
Last active August 29, 2015 14:13
Show Gist options
  • Save stephenwithav/2c105de102a9374c8aa1 to your computer and use it in GitHub Desktop.
Save stephenwithav/2c105de102a9374c8aa1 to your computer and use it in GitHub Desktop.
Fails with "invalid UTF-8 on line 1"
package main
import (
"bytes"
"log"
"net/http"
"strings"
"launchpad.net/xmlpath"
)
func main() {
// retrieve Google Alerts feed for "go"
resp, _ := http.Get("https://www.google.com/alerts/feeds/05850118961943884337/16879813453666049819")
buf := &bytes.Buffer{}
buf.ReadFrom(resp.Body)
s := buf.String()
t, err := xmlpath.Parse(strings.NewReader(s))
if err != nil {
log.Fatal("Failed.", err, t)
}
}
package main
import (
"bytes"
"encoding/xml"
"fmt"
"net/http"
"strings"
"unicode/ut8"
)
func main() {
resp, _ := http.Get("https://www.google.com/alerts/feeds/05850118961943884337/16879813453666049819")
buf := &bytes.Buffer{}
buf.ReadFrom(resp.Body)
s := buf.String()
fmt.Println(utf8.ValidString(s))
d := xml.NewDecoder(strings.NewReader(s))
for {
t, err := d.Token()
fmt.Printf("%T\n", t)
if err != nil {
fmt.Println(err)
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment