Skip to content

OPML Reference

OPML (Outline Processor Markup Language) is a format for exchanging outline-structured information, commonly used for sharing feed subscription lists.

Versions1.0, 2.0

Functions

parseOpml()

Parses OPML content and returns a typed OPML object.

typescript
import { parseOpml } from 'feedsmith'

const opml = parseOpml(xmlContent, {
  extraOutlineAttributes: ['customIcon', 'updateInterval']
})
// Returns: object with all fields optional and dates as strings

// Limit number of outlines parsed
const opml = parseOpml(xmlContent, { maxItems: 5 })

// Combine both options
const opml = parseOpml(xmlContent, {
  maxItems: 5,
  extraOutlineAttributes: ['customIcon', 'updateInterval']
})

Parameters

ParameterTypeDescription
contentstringThe OPML XML content to parse
optionsobjectOptional parsing settings

Options

OptionTypeDefaultDescription
maxItemsnumber-Limit the number of outlines parsed. Use 0 to skip outlines entirely, useful when only OPML metadata is needed
extraOutlineAttributesstring[]-Custom attributes to extract from outline elements (case-insensitive), see examples

Returns

object - Parsed OPML with all fields optional and dates as strings

generateOpml()

Generates OPML XML from OPML data.

typescript
import { generateOpml } from 'feedsmith'

const xml = generateOpml(opmlData, {
  lenient: true,
  stylesheets: [{ type: 'text/xsl', href: '/opml.xsl' }],
  extraOutlineAttributes: ['customIcon', 'updateInterval']
})

Parameters

ParameterTypeDescription
dataobjectOPML 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
extraOutlineAttributesstring[]-Custom attributes to include in outline elements. Only specified attributes are included in generated XML, see examples

Returns

string - Generated OPML XML

Types

All OPML types are available under the Opml namespace:

typescript
import type { Opml } from 'feedsmith/types'

// Access any type from the definitions below
type Document = Opml.Document<Date>
type Head = Opml.Head<Date>
type Body = Opml.Body<Date>
type Outline = Opml.Outline<Date>
// … see type definitions below for all available types

See the TypeScript guide for usage examples.

Type Definitions

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 namespace Opml {
  export type Outline<
    TDate extends DateLike,
    A extends ReadonlyArray<string> = ReadonlyArray<string>,
  > = {
    text: string
    type?: string
    isComment?: boolean
    isBreakpoint?: boolean
    created?: TDate
    category?: string
    description?: string
    xmlUrl?: string
    htmlUrl?: string
    language?: string
    title?: string
    version?: string
    url?: string
    outlines?: Array<Outline<TDate, A>>
  } & ExtraFields<A>

  export type Head<TDate extends DateLike> = {
    title?: string
    dateCreated?: TDate
    dateModified?: TDate
    ownerName?: string
    ownerEmail?: string
    ownerId?: string
    docs?: string
    expansionState?: Array<number>
    vertScrollState?: number
    windowTop?: number
    windowLeft?: number
    windowBottom?: number
    windowRight?: number
  }

  export type Body<
    TDate extends DateLike,
    A extends ReadonlyArray<string> = ReadonlyArray<string>,
  > = {
    outlines?: Array<Outline<TDate, A>>
  }

  export type Document<
    TDate extends DateLike,
    A extends ReadonlyArray<string> = ReadonlyArray<string>,
  > = {
    head?: Head<TDate>
    body?: Body<TDate, A>
  }
}

INFO

The Outline type includes an index signature [key: string]: unknown which allows storing any custom attributes alongside the standard OPML properties.