daniel-keogh / opml

A Dart package for parsing and building OPML documents

Home Page:https://pub.dev/packages/opml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

opml

Pub Build Status License: MIT

A Dart package for parsing and building OPML documents.

Installing

Import the package into your Dart code using:

import 'package:opml/opml.dart';

Examples

Parsing XML

To parse XML input, use the OpmlDocument.parse(String xmlString) factory:

final xmlString = """
<?xml version='1.0' encoding='UTF-8' ?>
<opml version="1.0">
  <head>
    <title>Example OPML Export</title>
  </head>
  <body>
    <outline text="World" title="World">
      <outline type="rss" text="BBC News - World" xmlUrl="http://feeds.bbci.co.uk/..." />
      <outline type="rss" text="World news | The Guardian" xmlUrl="http://feeds.guardian.co.uk/..." />
    </outline>
    <outline text="Uncategorized" title="Uncategorized" />
  </body>
</opml>
""";

final opml = OpmlDocument.parse(xmlString);

Converting to XML

You can convert an OpmlDocument object to XML by first constructing the object and then calling toXmlString() on it.

  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);

License

MIT

About

A Dart package for parsing and building OPML documents

https://pub.dev/packages/opml

License:MIT License


Languages

Language:Dart 100.0%