detectRssVersion static method
Implementation
static RssVersion detectRssVersion(String xmlString) {
final xmlDoc = xml.XmlDocument.parse(xmlString);
final rdfRefs = xmlDoc.findAllElements('rdf:RDF');
final rssRefs = xmlDoc.findAllElements('rss');
final feedRefs = xmlDoc.findAllElements('feed');
bool? ver = false;
bool? xmlns = false;
ver = rssRefs.isEmpty
? false
: rssRefs.first.getAttribute('version')?.contains('2');
xmlns = feedRefs.isEmpty
? false
: feedRefs.first.getAttribute('xmlns')?.toLowerCase()?.contains('atom');
if (rdfRefs.isNotEmpty) {
return RssVersion.RSS1;
} else if (rssRefs.isNotEmpty && ver != null && ver) {
return RssVersion.RSS2;
} else if (feedRefs.isNotEmpty && xmlns != null && xmlns) {
return RssVersion.Atom;
}
return RssVersion.Unknown;
}