detect_format

Function detect_format 

Source
pub fn detect_format(data: &[u8]) -> FeedVersion
Expand description

Auto-detect feed format from raw data

Examines the input data to determine the feed format by analyzing:

  1. Whether it’s JSON (starts with {) → JSON Feed
  2. Root XML element name and attributes → RSS or Atom

§Arguments

  • data - Raw feed data (XML or JSON)

§Returns

  • FeedVersion - Detected format, or Unknown if unrecognized

§Examples

use feedparser_rs::{detect_format, FeedVersion};

let rss = br#"<?xml version="1.0"?><rss version="2.0"></rss>"#;
assert_eq!(detect_format(rss), FeedVersion::Rss20);

let atom = br#"<feed xmlns="http://www.w3.org/2005/Atom"></feed>"#;
assert_eq!(detect_format(atom), FeedVersion::Atom10);