Rss1Feed.parse constructor

Rss1Feed.parse(
  1. String xmlString
)

Implementation

factory Rss1Feed.parse(String xmlString) {
  final document = XmlDocument.parse(xmlString);
  XmlElement rdfElement;
  try {
    rdfElement = document.findAllElements('rdf:RDF').first;
  } on StateError {
    throw ArgumentError('channel not found');
  }

  final channel = rdfElement.findElements('channel');
  return Rss1Feed(
    title: findElementOrNull(rdfElement, 'title')?.innerText,
    link: findElementOrNull(rdfElement, 'link')?.innerText,
    description: findElementOrNull(rdfElement, 'description')?.innerText,
    items: rdfElement
        .findElements('item')
        .map((element) => Rss1Item.parse(element))
        .toList(),
    image:
        findElementOrNull(rdfElement, 'image')?.getAttribute('rdf:resource'),
    updatePeriod: _parseUpdatePeriod(
      findElementOrNull(rdfElement, 'sy:updatePeriod')?.innerText,
    ),
    updateFrequency: parseInt(
      findElementOrNull(rdfElement, 'sy:updateFrequency')?.innerText,
    ),
    updateBase: parseDateTime(
      findElementOrNull(rdfElement, 'sy:updateBase')?.innerText,
    ),
    dc: channel.isEmpty
        ? null
        : DublinCore.parse(rdfElement.findElements('channel').first),
  );
}