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
SpecificationOPML 2.0 Specification

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, {
  stylesheets: [{ type: 'text/xsl', href: '/opml.xsl' }],
  extraOutlineAttributes: ['customIcon', 'updateInterval']
})

Parameters

ParameterTypeDescription
dataobjectOPML data to generate
optionsobjectOptional generation settings

Options

OptionTypeDefaultDescription
strictbooleanfalseEnable strict mode for spec-required field validation, see Strict 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'

// 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

For details on type parameters (TDate, TStrict) and Requirable<T> markers, see TypeScript Reference.

ts
export namespace Opml {
  // NOTE: BaseOutline contains non-recursive fields wrapped in Strict<>.
  // Outline extends it and adds recursive outlines field separately.
  export type BaseOutline<
    TDate extends DateLike,
    A extends ReadonlyArray<string> = ReadonlyArray<string>,
    TStrict extends boolean = false,
  > = Strict<
    {
      text: Requirable<string> // Required in spec.
      type?: string
      isComment?: boolean
      isBreakpoint?: boolean
      created?: TDate
      category?: string
      description?: string
      xmlUrl?: string
      htmlUrl?: string
      language?: string
      title?: string
      version?: string
      url?: string
    },
    TStrict
  > &
    ExtraFields<A>

  export type Outline<
    TDate extends DateLike,
    A extends ReadonlyArray<string> = ReadonlyArray<string>,
    TStrict extends boolean = false,
  > = BaseOutline<TDate, A, TStrict> & {
    outlines?: Array<Outline<TDate, A, TStrict>>
  }

  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>,
    TStrict extends boolean = false,
  > = {
    outlines?: Array<Outline<TDate, A, TStrict>>
  }

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

INFO

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