[][src]Struct easy_rss::RssParser

pub struct RssParser {
    pub node_tag: String,
    pub title_tag: String,
    pub link_tag: String,
    pub author_tag: String,
    pub description_tag: String,
    pub guid_tag: String,
    pub publish_tag: String,
    // some fields omitted
}

Rss Parse Utils

Parse Xml

use easy_rss::RssParser;

fn main()->Result<(),Box<dyn std::error::Error>>{
    let mut parser_default = RssParser::new();
    println!("{:?}",parser_default);
    parser_default.set_xml(String::from(
       r#"<?xml version="1.0" encoding="UTF-8" ?>
        <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
            <item>
                <title>Hey!</title>
                <link>examples.com</link>
                <description>hello.world!</description>
                <author>MeteorCat</author>
                <guid>unique key</guid>
                <pubDate>2020-05-28 15:00:00</pubDate>
            </item>
        </rss>
        "#
    ));
    println!("{:?}",parser_default.parse_vec()?);
    Ok(())
}

Parse Web XMl

use easy_rss::RssParser;

fn main()->Result<(),Box<dyn std::error::Error>> {
    let address = "https://www.zhihu.com/rss";
    let mut parser = RssParser::from_url(address,"utf8")?;
    parser.author_tag = String::from("dc:creator");
    let rss = parser.parse_vec()?;
    println!("{:?}",rss);
    Ok(())
}

RSS To Json

use easy_rss::RssParser;

fn main()->Result<(),Box<dyn std::error::Error>> {
    let address = "https://www.zhihu.com/rss";
    let mut parser = RssParser::from_url(address,"utf8")?;
    parser.author_tag = String::from("dc:creator");
    assert!(parser.parse_json().is_ok());
    Ok(())
}

Rss Request Builder

use easy_rss::RssParser;

fn main()->Result<(),Box<dyn std::error::Error>> {
    let address = "https://www.zhihu.com/rss";
    let charset = "utf8";
    let mut parser = RssParser::new();
    parser.author_tag = "dc:creator".into();
    parser.publish_tag = "pubDate".into();
    let xml = parser.request_xml(address,charset)?;
    parser.set_xml(xml);
    assert!(parser.parse_vec().is_ok());
    Ok(())
}

Fields

node_tag: Stringtitle_tag: Stringlink_tag: Stringauthor_tag: Stringdescription_tag: Stringguid_tag: Stringpublish_tag: String

Implementations

impl RssParser[src]

pub fn check_xml(&mut self) -> bool[src]

Todo: Optimization

pub fn request_xml(&mut self, url: &str, charset: &str) -> Result<String, Error>[src]

Request Rss by Web

pub async fn request_file<'_, '_>(
    &'_ mut self,
    filename: &'_ str
) -> Result<String, Error>
[src]

Request RSS by File

pub fn new() -> Self[src]

pub fn from_str(xml: String) -> Result<Self, Error>[src]

pub fn from_url(url: &str, charset: &str) -> Result<Self, Error>[src]

pub async fn from_file<'_>(filename: &'_ str) -> Result<Self, Error>[src]

pub fn parse_vec(&mut self) -> Result<Vec<RssItem>, Error>[src]

pub fn parse_json(&mut self) -> Result<String, Error>[src]

pub fn set_xml(&mut self, xml: String)[src]

pub fn get_xml(&self) -> &String[src]

Trait Implementations

impl Debug for RssParser[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.