AtomFeed.parse constructor

AtomFeed.parse(
  1. String xmlString
)

Parse constructor for the AtomFeed class, used when 'parsing' a feed

Implementation

factory AtomFeed.parse(String xmlString) {
  final document = XmlDocument.parse(xmlString);
  final feedElement = document.findElements('feed').firstOrNull;
  if (feedElement == null) {
    throw ArgumentError('feed not found');
  }

  return AtomFeed(
    id: feedElement.findElements('id').firstOrNull?.text,
    title: feedElement.findElements('title').firstOrNull?.text,
    updated:
        parseDateTime(feedElement.findElements('updated').firstOrNull?.text),
    items: feedElement.findElements('entry').map(AtomItem.parse).toList(),
    links: feedElement.findElements('link').map(AtomLink.parse).toList(),
    authors:
        feedElement.findElements('author').map(AtomPerson.parse).toList(),
    contributors: feedElement
        .findElements('contributor')
        .map(AtomPerson.parse)
        .toList(),
    categories:
        feedElement.findElements('category').map(AtomCategory.parse).toList(),
    generator: feedElement
        .findElements('generator')
        .map(AtomGenerator.parse)
        .firstOrNull,
    icon: feedElement.findElements('icon').firstOrNull?.text,
    logo: feedElement.findElements('logo').firstOrNull?.text,
    rights: feedElement.findElements('rights').firstOrNull?.text,
    subtitle: feedElement.findElements('subtitle').firstOrNull?.text,
  );
}