RssFeed.parse constructor
RssFeed.parse(
- String xmlString
Implementation
factory RssFeed.parse(String xmlString) {
final document = XmlDocument.parse(xmlString);
XmlElement channelElement;
try {
channelElement = document.findAllElements('channel').first;
} on StateError {
throw ArgumentError('channel not found');
}
return RssFeed(
title: findElementOrNull(channelElement, 'title')?.text,
author: findElementOrNull(channelElement, 'author')?.text,
description: findElementOrNull(channelElement, 'description')?.text,
link: findElementOrNull(channelElement, 'link')?.text,
items: channelElement.findElements('item').map((element) => RssItem.parse(element)).toList(),
image: RssImage.parse(findElementOrNull(channelElement, 'image')),
cloud: RssCloud.parse(findElementOrNull(channelElement, 'cloud')),
categories: channelElement.findElements('category').map((element) => RssCategory.parse(element)).toList(),
skipDays: findElementOrNull(channelElement, 'skipDays')
?.findAllElements('day')
.map((element) => element.text)
.toList() ??
<String>[],
skipHours: findElementOrNull(channelElement, 'skipHours')
?.findAllElements('hour')
.map((element) => int.tryParse(element.text) ?? 0)
.toList() ??
<int>[],
lastBuildDate: findElementOrNull(channelElement, 'lastBuildDate')?.text,
language: findElementOrNull(channelElement, 'language')?.text,
generator: findElementOrNull(channelElement, 'generator')?.text,
copyright: findElementOrNull(channelElement, 'copyright')?.text,
docs: findElementOrNull(channelElement, 'docs')?.text,
managingEditor: findElementOrNull(channelElement, 'managingEditor')?.text,
rating: findElementOrNull(channelElement, 'rating')?.text,
webMaster: findElementOrNull(channelElement, 'webMaster')?.text,
ttl: int.tryParse(findElementOrNull(channelElement, 'ttl')?.text ?? '0') ?? 0,
dc: DublinCore.parse(channelElement),
itunes: RssItunes.parse(channelElement),
podcastIndex: RssPodcastIndex.parse(channelElement),
);
}