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')?.text,
    link: findElementOrNull(rdfElement, 'link')?.text,
    description: findElementOrNull(rdfElement, 'description')?.text,
    items: rdfElement
        .findElements('item')
        .map((element) => Rss1Item.parse(element))
        .toList(),
    image:
        findElementOrNull(rdfElement, 'image')?.getAttribute('rdf:resource'),
    updatePeriod: _parseUpdatePeriod(
        findElementOrNull(rdfElement, 'sy:updatePeriod')?.text),
    updateFrequency:
        parseInt(findElementOrNull(rdfElement, 'sy:updateFrequency')?.text),
    updateBase:
        parseDateTime(findElementOrNull(rdfElement, 'sy:updateBase')?.text),
    dc: channel.isEmpty ? null : DublinCore.parse(rdfElement.findElements('channel').first),
  );
}