pub struct XmlParser;Expand description
A utility for parsing XML content.
This struct provides helper methods for common XML parsing operations used when extracting data from EPUB files (OPF, NCX, and HTML content).
Implementations§
Source§impl XmlParser
impl XmlParser
Sourcepub fn extract_text<R: BufRead>(
reader: &mut Reader<R>,
buf: &mut Vec<u8>,
) -> Result<Option<String>, Box<dyn Error>>
pub fn extract_text<R: BufRead>( reader: &mut Reader<R>, buf: &mut Vec<u8>, ) -> Result<Option<String>, Box<dyn Error>>
Extracts text content from an XML reader.
Reads events from the XML reader until a text event is found or
the element ends. This is useful for extracting the text content
of XML elements like <title>, <creator>, etc.
§Arguments
reader- The XML reader to read events from.buf- A buffer for reading events (will be cleared automatically).
§Returns
Returns Ok(Some(String)) if text was found, Ok(None) if no
text was found before the element ended, or an error if parsing fails.
§Errors
Returns an error if there is an XML parsing error.
§Example
use quick_xml::Reader;
use epub_parser::utils::XmlParser;
let xml = r#"<title>My Book</title>"#;
let mut reader = Reader::from_str(xml);
let mut buf = Vec::new();
// Skip the Start event
reader.read_event_into(&mut buf).unwrap();
let text = XmlParser::extract_text(&mut reader, &mut buf).unwrap();
assert_eq!(text, Some("My Book".to_string()));Auto Trait Implementations§
impl Freeze for XmlParser
impl RefUnwindSafe for XmlParser
impl Send for XmlParser
impl Sync for XmlParser
impl Unpin for XmlParser
impl UnsafeUnpin for XmlParser
impl UnwindSafe for XmlParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more