rss_gen::parser

Function parse_rss

source
pub fn parse_rss(content: &str) -> Result<RssData>
Expand description

Parses an RSS feed from XML content.

This function takes XML content as input and parses it into an RssData struct. It supports parsing RSS versions 0.90, 0.91, 0.92, 1.0, and 2.0.

§Arguments

  • content - A string slice containing the XML content of the RSS feed.

§Returns

  • Ok(RssData) - The parsed RSS data if successful.
  • Err(RssError) - An error if parsing fails.

§Example

use rss_gen::parse_rss;

let xml_content = r#"
    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0">
        <channel>
            <title>My Blog</title>
            <link>https://example.com</link>
            <description>A sample blog</description>
            <item>
                <title>First Post</title>
                <link>https://example.com/first-post</link>
                <description>This is my first post</description>
            </item>
        </channel>
    </rss>
"#;

let parsed_data = parse_rss(xml_content).unwrap();
assert_eq!(parsed_data.title, "My Blog");
assert_eq!(parsed_data.items.len(), 1);