rust-syndication / rss

Library for serializing the RSS web content syndication format
https://crates.io/crates/rss
Apache License 2.0
429 stars 53 forks source link

atom: Error: the input did not begin with an rss tag #163

Closed bbigras closed 5 months ago

bbigras commented 5 months ago

https://github.com/NixOS/nixpkgs/commits/nixos-unstable.atom

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
  <id>tag:github.com,2008:/NixOS/nixpkgs/commits/nixos-unstable</id>
  <link type="text/html" rel="alternate" href="https://github.com/NixOS/nixpkgs/commits/nixos-unstable"/>
  <link type="application/atom+xml" rel="self" href="https://github.com/NixOS/nixpkgs/commits/nixos-unstable.atom"/>
  <title>Recent Commits to nixpkgs:nixos-unstable</title>
  <updated>2024-06-05T15:53:02Z</updated>
    let rep = http_client
        .get(url.clone())
        .send()
        .await?
        .error_for_status()?;

    let content = rep.bytes().await?;

    let channel = rss::Channel::read_from(&content[..])?;
reqwest = "0.11.24"
rss = { version = "2.0.7", features = ["atom", "chrono", "serde", "with-serde"] }

EDIT:

I seem able to use atom_syndication directly.

    use atom_syndication::Feed;
    use std::fs::File;
    use std::io::BufReader;
    let channel = Feed::read_from(&content[..]).unwrap();
andy128k commented 5 months ago

RSS and Atom are distinct formats. You need to use atom crate instead.

bbigras commented 5 months ago

Ah thanks. I guess I thought that the rss supported atom since it has an atom feature.

andy128k commented 5 months ago

Nope. atom feature is to support some Atom tags inside of a regular RSS document.

There is another crate https://github.com/rust-syndication/syndication which combines Atom and RSS but it seems abandoned.