Skip to content
A syndication feed parser for Atom 1.0 and RSS 2.0 in Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_samples
.gitignore
.travis.yml
LICENSE
README.md
atom.go
atom_test.go
date.go
feed.go
feed_test.go
plugin.go
rss.go
rss_test.go

README.md

Overview

Coverage Status Go Report Card Build Status GoDoc MIT license

syndfeed is a Go library for RSS 2.0 and Atom 1.0 feeds, supported implement extension module to parse any RSS and Atom extension element.

Dependencies

Getting Started

Parse a feed from URL

feed, _ := syndfeed.LoadURL("https://cn.engadget.com/rss.xml")
fmt.Println(feed.Title)

Parse a feed from io.Reade

feedData := `<rss version="2.0">
<channel>
<title>Sample Feed</title>
</channel>
</rss>`
feed, _ := syndfeed.Parse(strings.NewReader(feedData))
fmt.Println(feed.Title)

Parse an Atom feed into syndfeed.Feed

feedData := `<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Atom</title>
</feed>`
feed, _ := syndfeed.ParseAtom(strings.NewReader(feedData))
fmt.Println(feed.Title)

Parse a RSS feed into syndfeed.Feed

feedData := `<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<dc:creator>example@site.com (Example Name)</dc:creator>
</channel>`
feed, _ := syndfeed.ParseRSS(strings.NewReader(feedData))
fmt.Println(feed.Authors[0].Name)

Extension Modules

In some syndication feeds, they have some valid XML elements but are not specified in either the Atom 1.0 or RSS 2.0 specifications. You can add extension module to process these elements.

The syndfeed build-in supported following modules: Dublin Core, Content, Syndication.

You can implement your own modules to parse any extension element like: iTunes RSS, Media RSS.

iTunes Module

iTunesHandler := func(n *xmlquery.Node, v interface{}) {
    item := v.(*syndfeed.Item)
    switch n.Data {
    case "artist":
        item.Authors = append(item.Authors, &syndfeed.Person{Name: n.InnerText()})
    case "releaseDate":
		item.PublishDate = ParseDate(n.InnerText())
    }
}
// Register a new module to the syndfeed module list.
syndfeed.RegisterExtensionModule("https://rss.itunes.apple.com", syndfeed.ModuleHandlerFunc(iTunesHandler))
// Now can parse iTunes feed. 
feed, err := syndfeed.LoadURL("https://github.com/zhengchun/syndfeed/blob/master/_samples/itunes.atom")
fmt.Println(feed.Items[0].Authors[0].Name)
// Output author name.

TODO

  • Add RSS/Atom format output.

Please let me know if you have any questions.

You can’t perform that action at this time.