Skip to content

RSS Feed Reference

RSS (Really Simple Syndication) is one of the most widely used web feed formats. Feedsmith automatically normalizes legacy elements to their modern equivalents.

Versions0.9x, 2.0
NamespacesAtom, Dublin Core, Syndication, Content, Slash, iTunes, Podcast, Podlove Simple Chapters, Media RSS, GeoRSS-Simple, Atom Threading, Dublin Core Terms, Well-Formed Web, Source

Functions

parseRssFeed()

Parses RSS feed content and returns a typed RSS object.

typescript
import { parseRssFeed } from 'feedsmith'

const rssFeed = parseRssFeed(xmlContent)
// Returns: object with all fields optional and dates as strings

Parameters

ParameterTypeDescription
contentstringThe RSS XML content to parse

Returns

object - Parsed RSS feed with all fields optional and dates as strings

generateRssFeed()

Generates RSS XML from feed data.

typescript
import { generateRssFeed } from 'feedsmith'

const xml = generateRssFeed(feedData, {
  lenient: true,
  stylesheets: [{ type: 'text/xsl', href: '/feed.xsl' }]
})

Parameters

ParameterTypeDescription
dataobjectRSS feed data to generate
optionsobjectOptional generation settings

Options

OptionTypeDefaultDescription
lenientbooleanfalseEnable lenient mode for relaxed validation, see Lenient Mode
stylesheetsStylesheet[]-Add stylesheets for visual formatting, see Feed Styling

Returns

string - Generated RSS XML

detectRssFeed()

Detects if the provided content is an RSS feed.

Parameters

ParameterTypeDescription
contentstringThe content to check

Returns

boolean - true if content appears to be RSS format

Example

typescript
import { detectRssFeed } from 'feedsmith'

const isRss = detectRssFeed(xmlContent)

Types

INFO

TDate represents date fields in the type definitions. When parsing, dates are returned as strings in their original format (see Parsing › Handling Dates for more details). When generating, dates should be provided as JavaScript Date objects.

ts
export type Person = string

export type Category = {
  name: string
  domain?: string
}

export type Cloud = {
  domain: string
  port: number
  path: string
  registerProcedure: string
  protocol: string
}

export type Image = {
  url: string
  title: string
  link: string
  description?: string
  height?: number
  width?: number
}

export type TextInput = {
  title: string
  description: string
  name: string
  link: string
}

export type Enclosure = {
  url: string
  length: number
  type: string
}

export type SkipHours = Array<number>

export type SkipDays = Array<string>

export type Guid = {
  value: string
  isPermaLink?: boolean
}

export type Source = {
  title: string
  url?: string
}

export type Item<TDate extends DateLike> = {
  title?: string
  link?: string
  description?: string
  authors?: Array<Person>
  categories?: Array<Category>
  comments?: string
  enclosures?: Array<Enclosure>
  guid?: Guid
  pubDate?: TDate
  source?: Source
  atom?: AtomEntry<TDate>
  dc?: DcItemOrFeed<TDate>
  content?: ContentItem
  slash?: SlashItem
  itunes?: ItunesItem
  podcast?: PodcastItem
  psc?: PscItem
  media?: MediaItemOrFeed
  georss?: GeoRssItemOrFeed
  thr?: ThrItem
  dcterms?: DctermsItemOrFeed<TDate>
  wfw?: WfwItem
  src?: SourceItem
} & ({ title: string } | { description: string })

export type Feed<TDate extends DateLike> = {
  title: string
  // INFO: Spec mentions required "link", but the "link" might be missing as well when the
  // atom:link rel="self" is present so that's why the "link" is not required in this type.
  link?: string
  description: string
  language?: string
  copyright?: string
  managingEditor?: Person
  webMaster?: Person
  pubDate?: TDate
  lastBuildDate?: TDate
  categories?: Array<Category>
  generator?: string
  docs?: string
  cloud?: Cloud
  ttl?: number
  image?: Image
  rating?: string
  textInput?: TextInput
  skipHours?: Array<number>
  skipDays?: Array<string>
  items?: Array<Item<TDate>>
  atom?: AtomFeed<TDate>
  dc?: DcItemOrFeed<TDate>
  sy?: SyFeed<TDate>
  itunes?: ItunesFeed
  podcast?: PodcastFeed<TDate>
  media?: MediaItemOrFeed
  georss?: GeoRssItemOrFeed
  dcterms?: DctermsItemOrFeed<TDate>
  src?: SourceFeed
}