AtomFeed.parse constructor
Parse constructor for the AtomFeed class, used when 'parsing' a feed
If parseHtml
is true, HTML tags will be parsed from the feed
Implementation
factory AtomFeed.parse(String xmlString, [bool parseHtml = true]) {
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?.innerText,
title:
feedElement.findElements('title').firstOrNull?.parseText(parseHtml),
updated: parseDateTime(
feedElement.findElements('updated').firstOrNull?.innerText,
),
items: feedElement
.findElements('entry')
.map((item) => AtomItem.parse(item, parseHtml))
.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?.innerText,
logo: feedElement.findElements('logo').firstOrNull?.innerText,
rights: feedElement.findElements('rights').firstOrNull?.innerText,
subtitle: feedElement
.findElements('subtitle')
.firstOrNull
?.parseText(parseHtml),
);
}