Skip to main content

parse_str_with_options

Function parse_str_with_options 

Source
pub fn parse_str_with_options(
    text: &str,
    options: &ParseOptions,
) -> Result<ParsedFeed>
Expand description

Parse an already decoded string, ignoring any declared encoding.

Use it when the caller holds text rather than bytes, so no charset detection can misread it: an XML declaration label is ignored, one leading U+FEFF is stripped, encoding is "utf-8" and decoding never sets bozo. Everything else matches parse_with_options.

§Errors

Same as parse_with_options.

§Examples

use feedparser_rs::{ParseOptions, parse_str_with_options};

let xml = r#"<?xml version="1.0" encoding="gbk"?>
<rss version="2.0"><channel><title>héllo</title></channel></rss>"#;
let feed = parse_str_with_options(xml, &ParseOptions::default())?;
assert_eq!(feed.feed.title.as_deref(), Some("héllo"));
assert_eq!(feed.encoding, "utf-8");