From 66eea2e6af57b2abcbb481f4f85f9e50ec66a54b Mon Sep 17 00:00:00 2001 From: Matthew Dawson Date: Fri, 25 Oct 2013 23:26:15 -0400 Subject: [PATCH] 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. --- rss.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rss.go b/rss.go index eb8d359..763593e 100644 --- a/rss.go +++ b/rss.go @@ -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)