opml 0.4.0 copy "opml: ^0.4.0" to clipboard
opml: ^0.4.0 copied to clipboard

A Dart package for parsing and building Outline Processor Markup Language (OPML) documents.

example/main.dart

import 'dart:io';

import 'package:opml/opml.dart';

void main() {
  print('Reading example...\n');
  readExample();

  print('\nWriting example...\n');
  writeExample();
}

/// Reads a local OPML file and prints some properties.
void readExample() {
  final xml = File('example/example.xml').readAsStringSync();

  final doc = OpmlDocument.parse(xml);

  print('${doc.head.title}:');

  for (var category in doc.body) {
    for (var feed in category.children!) {
      print('- ${feed.title} : ${feed.xmlUrl}');
    }
  }
}

/// Creates an OpmlDocument object and prints it to the screen as XML.
void writeExample() {
  final head = OpmlHeadBuilder().title('Example Export').build();
  final body = <OpmlOutline>[];

  body.add(OpmlOutlineBuilder()
      .text('World')
      .title('World')
      .addChild(OpmlOutlineBuilder()
          .type('rss')
          .text('BBC News - World')
          .title('BBC News - World')
          .xmlUrl('http://feeds.bbci.co.uk/news/world/rss.xml')
          .build())
      .addChild(OpmlOutlineBuilder()
          .type('rss')
          .text('World news | The Guardian')
          .title('World news | The Guardian')
          .xmlUrl('http://feeds.guardian.co.uk/theguardian/world/rss')
          .build())
      .build());

  body.add(OpmlOutlineBuilder()
      .text('Uncategorized')
      .title('Uncategorized')
      .build());

  final opml = OpmlDocument(
    head: head,
    body: body,
  );

  final xml = opml.toXmlString(pretty: true);

  print(xml);
}
5
likes
145
points
84
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for parsing and building Outline Processor Markup Language (OPML) documents.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

xml

More

Packages that depend on opml