Fix RSS feed parsing due to changes in go-pkg-xmlx.

Due to the PR jteeuwen/go-pkg-xmlx#16, when using SelectNodes there is no
longer any hidden recursion.  Due to RSS's structure, there is a root document
node.  These two pieces break the RSS parsing.  Fix by first selecting the
root document node, and then selecting the channels for parsing.
This commit is contained in:
Matthew Dawson 2013-10-25 23:26:15 -04:00
parent 20d050f908
commit 66eea2e6af
1 changed files with 15 additions and 2 deletions

17
rss.go
View File

@ -1,6 +1,10 @@
package feeder
import xmlx "github.com/jteeuwen/go-pkg-xmlx"
import (
"errors"
xmlx "github.com/jteeuwen/go-pkg-xmlx"
)
func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
days := make(map[string]int)
@ -34,7 +38,16 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
var list, tl []*xmlx.Node
const ns = "*"
channels := doc.SelectNodes(ns, "channel")
root := doc.SelectNode(ns, "rss")
if root == nil {
root = doc.SelectNode(ns, "RDF")
}
if root == nil {
return errors.New("Failed to find rss/rdf node in XML.")
}
channels := root.SelectNodes(ns, "channel")
for _, node := range channels {
if ch = getChan(node.S(ns, "pubDate"), node.S(ns, "title")); ch == nil {
ch = new(Channel)