A syndication feed parser for Atom 1.0 and RSS 2.0 in Go

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>[email protected] (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.

Similar Resources

A NMEA parser library in pure Go

go-nmea This is a NMEA library for the Go programming language (Golang). Features Parse individual NMEA 0183 sentences Support for sentences with NMEA

Dec 20, 2022

TOML parser for Golang with reflection.

THIS PROJECT IS UNMAINTAINED The last commit to this repo before writing this message occurred over two years ago. While it was never my intention to

Dec 30, 2022

User agent string parser in golang

User agent parsing useragent is a library written in golang to parse user agent strings. Usage First install the library with: go get xojoc.pw/userage

Aug 2, 2021

Simple HCL (HashiCorp Configuration Language) parser for your vars.

HCL to Markdown About To write a good documentation for terraform module, quite often we just need to print all our input variables as a fancy table.

Dec 14, 2021

A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured.

goldmark A Markdown parser written in Go. Easy to extend, standards-compliant, well-structured. goldmark is compliant with CommonMark 0.29. Motivation

Dec 29, 2022

A PDF renderer for the goldmark markdown parser.

A PDF renderer for the goldmark markdown parser.

goldmark-pdf goldmark-pdf is a renderer for goldmark that allows rendering to PDF. Reference See https://pkg.go.dev/github.com/stephenafamo/goldmark-p

Jan 7, 2023

Experimental parser Angular template

Experimental parser Angular template This repository only shows what a parser on the Go might look like Benchmark 100k line of template Parser ms @ang

Dec 15, 2021

A dead simple parser package for Go

A dead simple parser package for Go

A dead simple parser package for Go V2 Introduction Tutorial Tag syntax Overview Grammar syntax Capturing Capturing boolean value Streaming Lexing Sta

Dec 30, 2022

Freestyle xml parser with golang

fxml - FreeStyle XML Parser This package provides a simple parser which reads a XML document and output a tree structure, which does not need a pre-de

Jul 1, 2022
Watches container registries for new and changed tags and creates an RSS feed for detected changes.

Tagwatch Watches container registries for new and changed tags and creates an RSS feed for detected changes. Configuration Tagwatch is configured thro

Jan 7, 2022
Svenska-yle-rss-content-fixer - Attach content to Svenska Yle RSS feeds

svenska-yle-rss-content-fixer This little tool attaches article content to the S

Oct 4, 2022
iTunes and RSS 2.0 Podcast Generator in Golang

podcast Package podcast generates a fully compliant iTunes and RSS 2.0 podcast feed for GoLang using a simple API. Full documentation with detailed ex

Dec 23, 2022
This command line converts thuderbird's exported RSS .eml file to .html file

thunderbird-rss-html This command line tool converts .html to .epub with images fetching. Install > go get github.com/gonejack/thunderbird-rss-html Us

Dec 15, 2021
Colored RSS feeds in your console

RSS Console Feed Read colored rss feeds in your console Usage ./rss-console-feed

Dec 22, 2021
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.

omniparser Omniparser is a native Golang ETL parser that ingests input data of various formats (CSV, txt, fixed length/width, XML, EDI/X12/EDIFACT, JS

Jan 4, 2023
A shell parser, formatter, and interpreter with bash support; includes shfmt

sh A shell parser, formatter, and interpreter. Supports POSIX Shell, Bash, and mksh. Requires Go 1.14 or later. Quick start To parse shell scripts, in

Dec 29, 2022
A simple CSS parser and inliner in Go

douceur A simple CSS parser and inliner in Golang. Parser is vaguely inspired by CSS Syntax Module Level 3 and corresponding JS parser. Inliner only p

Dec 12, 2022
Unified diff parser and printer for Go

go-diff Diff parser and printer for Go. Installing go get -u github.com/sourcegraph/go-diff/diff Usage It doesn't actually compute a diff. It only rea

Dec 14, 2022
Quick and simple parser for PFSense XML configuration files, good for auditing firewall rules

pfcfg-parser version 0.0.1 : 13 January 2022 A quick and simple parser for PFSense XML configuration files to generate a plain text file of the main c

Jan 13, 2022