RReverser / serde-xml-rs

xml-rs based deserializer for Serde (compatible with 1.0+)
https://crates.io/crates/serde-xml-rs
MIT License
272 stars 90 forks source link

Parse error whlist parsing hackernoon xml feed #211

Open n1rjal opened 1 year ago

n1rjal commented 1 year ago

Hello everyone, I got an error while parsing hackernoon page. The error looks like the following. Here is my serde struct for upto the point where it failed.

#[derive(Serialize, Deserialize, Debug)]
pub struct Rss {
    channel: Channel,
}

#[derive(Debug, Serialize, Deserialize)]
struct Channel {
    #[serde(default)]
    title: String,

    #[serde(default)]
    description: String,

    #[serde(default)]
    image: Option<Image>,

    #[serde(default)]
    item: Vec<Item>,

    #[serde(skip)]
    #[serde(rename = "snf:logo")]
    logo: Option<String>,
}

My console says that the error was the following,

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SerdeError(Syntax { source: Error { pos: 15:18, kind: Syntax("Element snf:logo prefix is unbound") } })', src/main.rs:13:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[Finished running. Exit status: 101]

Regarding the error, I am unsure of how is this an error, seems like the package is complaing that the xml feed is not following correct syntax or is there any way to solve this. Thankyou. The hackernoon xml feed can be found below till the part which cause the syntax error.

<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title><![CDATA[Hacker Noon]]></title>
        <description><![CDATA[How hackers start their afternoons.]]></description>
        <link>https://hackernoon.com</link>
        <image>
            <url>https://hackernoon.com/hn-icon.png</url>
            <title>Hacker Noon</title>
            <link>https://hackernoon.com</link>
        </image>
        <generator>RSS for Node</generator>
        <lastBuildDate>Mon, 18 Sep 2023 10:00:14 GMT</lastBuildDate>
        <atom:link href="https://hackernoon.com/feed" rel="self" type="application/rss+xml"/>
        <pubDate>Mon, 18 Sep 2023 10:00:12 GMT</pubDate>
        <snf:logo>https://hackernoon.com/hn-logo.png</snf:logo>