Crates.io | fb2 |
lib.rs | fb2 |
version | 0.4.4 |
source | src |
created_at | 2023-07-02 17:52:18.205714 |
updated_at | 2023-10-07 07:29:52.285237 |
description | Parser of the FB2 format |
homepage | https://github.com/r-glazkov/fb2 |
repository | https://github.com/r-glazkov/fb2 |
max_upload_size | |
id | 906249 |
size | 1,420,801 |
This library is a set of models that enable quick-xml to deserialize an FB2 file in a structured way. The library tries to parse an invalid FB2, fix it, and output a valid one. That's because plenty of real FB2 books don't follow the standard... We can either ignore invalid elements, fail deserialization, or accept them and try to map them to the standard schema. This model tries to follow the third approach where it makes sense. The library model almost conforms to the standard XSD schema with a few exceptions:
Rc<Binary>
The current version of the model enables quick-xml to deserialize 95% of FB2 files if not more.
use fb2::FictionBook;
use std::fs::File;
use std::io::BufReader;
fn main() {
let file = File::open("examples/books/churchill_trial.fb2").unwrap();
let reader = BufReader::new(file);
let book: FictionBook = quick_xml::de::from_reader(reader).unwrap();
println!("{:#?}", book);
}
Try with:
cargo run --example parse_sample
Enable the encoding
feature of quick-xml:
quick-xml = { version = "<version>", features = ["encoding", "serialize"] }
Then, deserialize as usual.